In Android's Geocoder, method getFromLocation can return more than one address for a given lat long. But lat long uniquely represents a location on earth surface, so why does it return multiple objects?
Reverse geocoding translates latitude, longitude into a human-readable address. However, there are different objects that you may be interested in. For example, you can search the nearest street address, the nearest postal code, the neighborhood, the city, etc. For this reason reverse geocoder returns more than one result.
Please look at this example in the Geocoder tool.
As you can see the first result has a type street_address, the second result has a type bus_station, the third has a type neighborhood, and so on until the country level.
Hope my answer addresses your doubts.
Because a lat long position might not have a proper name, or it might refer to different names altogether.
Let's say, it points to the exact center of a square of undeveloped land, surrounded by 4 streets.
Depending on a country's rules & regulations, the owner of the land might be forced to 'attach' that piece of land to one of the 4 streets... or the land might be 'address-less' (only defined by its boundaries). In the latter case, the land might be attached to all 4 streets, allowing future purchaser/developer to choose the most 'catchy' address.
Or, a building just got renamed. For awhile, people won't recognize the new name. It's just wiser for reverse geocoding to return both the old name and the new name.
Another possibility is for the reverse geocoding to return "defined" names within X meters around the lat long position.
Related
I'm currently building a location based app that relies on the lat and long of the devices being properly translated to a text location.
My current problem is as follows (using lat/long -37.8047079,144.9641467 as an example):
Both
Places API
https://maps.googleapis.com/maps/api/place/textsearch/json?query=-37.8047079,144.9641467&key
and
Geocode API
https://maps.googleapis.com/maps/api/geocode/json?address=-37.8047079,144.96414677&key
return: "8-14 Little Queensberry St, Carlton VIC 3053, Australia"
However for some reason or another when the same lat long is typed into google maps itself it results in the location 135 Queensberry St, Carlton VIC 3053
Which is a major problem for me due to the routes API returning that same later address Causing a mismatch between the two services
Am i doing something wrong and if i'm not, is there a way around it?
Note that the second address is the one that i deem as "correct"
Thanks in advance !
When you execute a reverse geocoding you should use latlng parameter instead of the address parameter. So the query
https://maps.googleapis.com/maps/api/geocode/json?latlng=-37.8047079%2C144.96414677&key=MY_API_KEY
returns several items. The first one is Shop2/143 Queensberry St, Carlton VIC 3053 of type establishment, restaurant and the second one is 135 Queensberry St, Carlton VIC 3053, Australia of type street_address.
You can see these results in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D-37.804708%252C144.964147
It looks like restaurant is closer to the coordinate that you provided. However if your intention is getting back a street address just filter the reverse geocoding results by street address type.
https://maps.googleapis.com/maps/api/geocode/json?latlng=-37.8047079%2C144.96414677&result_type=street_address&key=YOUR_API_KEY
This request will return expected result.
I hope this helps!
I'm using Android's Geocoder to get street and suburb for my App, however on some roads, it will return State Route 60 for example, rather than the actual road name.
I'm in Western Australia if that makes any difference.
Is there a way around that ?
Or will I have to guess the street based on latitude and longitude ?
And in the same vein - the Geocoder returns streets as "St" and Roads as "Rd".
I can't find a default way of expanding that. If there is one, I would love to know about it.
I ended up changing the amount of addresses that the getFromLocation method returned to 2, and then adding logic in to detect when the first address is returned contained State Route.
When the first address returned State Route, it would use the second returned address instead.
As I am typing autocomplete address using http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=** I would like to prioritize within that city any address that begins with the following name .For ex: if I type mount and priority is California then it should give back Mountain view as the recommendation answer.How do I do that .I really appreciate any help.PLease let me know with respect to the above api call.Thanks in advance.
See https://developers.google.com/maps/documentation/geocoding/#Viewports
The short of it is that you can add a 'bounds' parameter that specifies lat-lng points to hint to the geocoder that you wish to look within a particular area. An example from that page is:
http://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&bounds=34.172684,-118.604794|34.236144,-118.500938&sensor=false
In my app, I have a list of locations, and I want to create filter settings. I am looking for a way so that a user can pick maybe a continent or country or address and then filter out the locations from the list if the location is within the continent or country or close to the address.
Is there a google maps v2 api for android that can do something like:
public Boolean AddressIsContained(String address, String place);
which returns true if address is within place (place could be like a country or continent). And also like
public Boolean AddressCloseTo(String address1, String address2, int distance);
which returns true if address1is within distance amount of kilometers to address2. And this would just be a straight line between the addresses, nothing like a bike, walk, car or plane route.
Also for the list of locations, I am also able to access its lat/long if that makes it easier.
Thanks
For the start I assume you are familiar with the GeoCoder and / or GeoCoding API to get the addresses for your locations.
If you use the GeoCoder you will get a List of Address objects. The Address class provides some methodes to get the country or city name f.e. These methods you can use for your filter.
The Location class includes the methods distanceBetween() and distanceTo(). These you can use to check the distance between your locations.
Hello I want to search nearest location using google place api....
from https://developers.google.com/places/documentation/supported_types i have used types in my code for searching nearest places....
and the code is below
try {
double radius = 5000; // 10000 meters
// get nearest places
nearPlaces = googlePlaces
.search(gps.getLatitude(), gps.getLongitude(), radius,
"sublocality|sublocality_level_4|sublocality_level_5|sublocality_level_3|sublocality_level_2|sublocality_level_1|neighborhood|locality|sublocality");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
but could not find nearest places
like if i am in "San Diego, CA, USA" then i want to get result like
Gaslamp/Downtown,
Pacific Beach,
Ocean Beach,
Uptown,
Hillcrest,
Mission Valley,
Fashion Valley,
North Park,
but instead of this i am getting only two value like
Mission Valley East,
Serra Mesa
so can any one help me what type i have to pass so i can get result like above instead of below result
My previous answer was deleted by a moderator for unknown reasons, I am re-posting with some more context as it is the currently the correct answer:
It appears you are trying return nearby geographical locations (anything from the second list in the supported place types). Unfortunately the Places API is not designed for this, it is designed to return a list of nearby establishments (anything from the first list in the supported place types) and up to two locality or political type results to to help identify the area you are performing a Place Search request for.
This is stated in the documentation here:
https://developers.google.com/places/documentation/search#PlaceSearchResponses
"results" contains an array of Places, with information about each. See Place Search Results for information about these results. The Places API returns up to 20 establishment results per query. Additionally, political results may be returned which serve to identify the area of the request.
If you type filter your Place Search request by a geographic location type like locality or political, you will filter out the establishment results and only be left with the area identity results.
A Places API - Feature Request for returning nearby localities has been filed here:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4434
If you believe this would be a useful feature please make sure your star the request to let us know you are interested in seeing it added.
double radius = 5000 is 5 Kilometers just over 3 miles.
If you increase the radius you should return more places
You should consider the distance to maximum 50Km and there are different types as follows:
establishment,lodging,spa,bar,church,place_of_worship etc.