I have a web view that shows google maps on my android activity. I am currently getting the link that contains the latitude and longitude values of the selected location by clicking a button. What I want to know is, how can I extract and save the latitude and longitude values in to variables? I tried this code but it doesn't seem to work
Uri uri = Uri.parse(str);
uri.getQueryParameter(q1);
If you have the url as a String, named str:
String[] part1 = str.split(Pattern.quote("#"));
String[] part2 = part1[1].split(Pattern.quote(","));
double lat = Double.parseDouble(part2[0]);
double lon = Double.parseDouble(part2[1]);
Related
I'm working on an application where I have a ListView that shows the coordinates of my smartphone's position previously stored on a database. The rows of the ListView appear to be like: (latitude, longitude), date.
Is it possible to get the single values of the item? I was thinking to retrieve only the latitude and longitude values of the clicked item so that I can open a new MapsActivity that sets a marker at those specific coordinates.
Looking through other similar questions I've got that with ((TextView) view).getText() or with listView.getItemAtPosition(position) I can read the entire content of the item, but I'd like to apply that to the first two values of the ListView.
So for anyone interested I solved my problem by parsing the content of the item as a String by doing like this:
String str = (String) listView.getItemAtPosition(position);
String parts[] = str.split(",");
String lat = parts[0];
String lon = parts[1];
I had to get rid of "(" and ")" in the visualization of the coordinates as they were hindering the string parsing.
I'm trying to get the exact URL of my current location showing my gps location as a marker on the map.
You could use a link in this format:
https://www.google.com/maps/search/?api=1&query=36.26577,-92.54324
and add the latitude and longitude of your location in the place of 36.26577 and -92.54324 respectively.
http://maps.google.com/?q=<lat>,<lng>
Use the above format, pass your values of lat and lng to the above URL format.
You can use it with android Intent as.
String geoUri = "http://maps.google.com/maps?q=loc:" + <lat-long>;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
startActivity(intent);
or simply URL
"http://maps.google.com/maps?q=loc:" + <lat-long>;
i am making a sample App where a Multi markers are on Google Map on Button click i want to store all latitude longitude of each marker in Array List but one marker position is saved on per for loop length can any one tell me how to store a each marker latitude longitude pair in Array?
for (int i=0; i<StopElement.Stop_name_list.size(); i++)
{
position = _Stop_marker.getPosition();
GETLatLng = position.toString();
_getlatlng = GETLatLng.substring(10, GETLatLng.length() - 1);
get_coordinates.add(_getlatlng);
}
I'm working on finding nearby places in my Android app. I can find the current latitude and longitude as a double and then converting the double into a string to display in a textview (just to prove to myself that it's working). The problem I'm having is passing the lat. & long. strings into the Places URL. The URL displays the JSON data when I use a fixed value string for the lat. and long., but it returns INVALID_REQUEST when I try to pass the obtained doubles converted into strings into the URL. Here's what it looks like:
Location currentLocation;
double currLatitude;
double currLongitude;
String latString;
String longiString;
String latString2 = "30.4335320";
String longiString2 = "-97.9822360";
towers = locMan.getBestProvider(criteria, true);
currentLocation = locMan.getLastKnownLocation(towers);
currLatitude = currentLocation.getLatitude();
currLongitude = currentLocation.getLongitude();
latString = String.valueOf(currLatitude);
longiString = String.valueOf(currLongitude);
latiText.setText(latString);
longiText.setText(longiString);
I think maybe I'm not parsing the doubles into strings correctly here?
latString = String.valueOf(currLatitude);
longiString = String.valueOf(currLongitude);
because in the below URL when I use the parsed values latString, longiString that's when I get INVALID_REQUEST, but if I pass latString2, longiString2, which are given values, the URL displays the JSON data. Here's the URL:
String tURL="https://maps.googleapis.com/maps/api/place/search/json?"
+ "location=" + latString + "," + longiString
+ "&radius=25000&"
+ "types=church&name=baptist&sensor=false&key="
+ myPlaceKey;
I fugured it out. My problem was that the activity that returned the URL was a separate Activity from the URL string builder. And the URL returning Activity did not call the method where I obtained the latitude and longitude, so I think the URL the returning Activity obtained basically had "null" for the coordinates. So I combined the two Activities so now the coordinates are obtained, then the URL is built, then the URL result is displayed in a textview, all in one Activity - and it WORKS! I'm such an idiot!
In Google Maps how can we get Latitude and Longitude by passing the Address?
and what is the Address format need to be mentioned?
To find latitude and longitude from address string .....
Make object of Geocoder
Call getFromLocationName() pass the address (place name) string as argument also maximum number of results you want for that place name
Here is demo ...
Geocoder coder = new Geocoder(LocationMap.this);
List<Address> geocodeResults = coder.getFromLocationName(placeName, 10);
Iterator<Address> locations = geocodeResults.iterator();
while (locations.hasNext()) {
Address loc = locations.next();
_lattitude_ = loc.getLatitude() ;
_longidude_ = loc.getLongitude();
}
And there are no specific address format required.
For example you can try any city name, country name, hotel name, area name, road name, well known place name ( Try "Eiffel tower") ... anything (from many things).
Found this older post. Should solve your problem.