We are using Google places android API to allow our users to use the autocomplete widget in order to quickly select addresses.
The widget itself returns a Google Place object which exposes a getAddress() method to return a human readable address string.
Is there a way to extract the address fields (street, city, state etc') from the Place object?
Using the lat/long for reverse geocoding is not 100% accurate (we saw cases where the house number was different).
Thank you.
Related
http://maps.google.com/maps/api/geocode/json?sensor=false&address=
I was looking at the above api and trying to find the location of the address "Grand Copthorne Hotel"..
However the result I am getting in the api is as follows
"status" : "ZERO_RESULTS"
Please let me know why this is taking place as it is affecting my entire platform and if its a problem from your end when should I expect the issue to be solved
Please let me know about the above issue
Geocoding API filters out businesses, it works only with street addresses.
If you need the location of the business you have to use Places API search.
E.g.
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Grand%20Copthorne%20Hotel&key=YOUR_API_KEY
Please refer to the documentation for further details:
https://developers.google.com/places/web-service/search
The Google Geocode API filters out businesses and only works on addresses. You said you have a valid address, but "Grand Copthorne Hotel" is not a valid address. An address provides enough information to mail something to a specific person or business.
If you want to retrieve location information with a generic search term, you should use a different API.
You can try some searches in the Google Places API search box; maybe that is a good API for your situation. It returns lots of information, including latitude and longitude. Check out the documentation.
The first thing you should do is discover and decide what kind of API you actually need. Do you need information for product shipping? Do you need to show a map to a user? Do you need to retrieve businesses' information?
Keep in mind that there are many kinds of location searches and varying services that return latitude and longitude. For instance, there is geocoding (generally matches addresses or partial addresses to a fairly accurate latitude and longitude pair); there is address validation (matches addresses to a database of information—probably postal service information—to provide very accurate location information for real addresses); there is places search (search for names, icons, titles, or business terms and retrieve location information). There are still other options. Just take a look at one list of mapping-related APIs from Google...
Full disclosure: I work for SmartyStreets, an address validation service.
In my android app, I find the address of locations using Geocoder.getFromLocation(). I can get an Address object and get the address lines of an address with Address.getAddressLine().
I am only interested in the first address line, which I can get easily with Address.getAddressLine(0).
Also, app allows user to choose locations using PlaceAutocomplete. When user chooses a location, I receive a Place object and I can get the address by Place.getAddress().
The problem is, Place.getAddress() returns a string instead of an Address object. This string contains the full address, so I cannot easily get the first address line, as I did with Address object.
How should I find the first address line from string returned by Place.getAddress()?
Short answer is that you can't get structured data from that API. For some reason, Google has decided that is not something people would want on Android.
A colleague of mine has logged this issue with Google to request the same level of information as is provided to iOS and JavaScript users:
Issue 10019: Expose address components in Place object
Longer answer is that your options are:
You figure out a clever way to parse that string. Unfortunately the actual street/suburb/town/province structure is not consistent across different areas (e.g. Cape Town in South Africa has a different sentence structure to Johannesburg in South Africa). So your parsing rules need to be very clever.
You use a different Google API. The JavaScript API provides structured data for the related call. This related question shows more details on that API. Unfortunately Google recommends against using this technique.
I believe that Google only intends to give us this sentence for the purposes of picking an address, rather than for us to get structured information about the address. In order to get better information, you need to get the lat/lng values by querying the place ID.
From those lat/lng values, you can then reverse-geolocate to get the correct address.
Unfortunately in this technique, Google's APIs fail us once more.
often you can take address A, resolve it to a given lat/lng, and resolve that to another address B, which might be close to A, but is not. The API calls are not commutative as one would expect
I have had a fair amount of experience with these calls, and I wish there was another answer I could provide. If you wish to stick with Google's location APIs, then you can't get what you are asking for.
Now it is impossible with this API only.
But you can use Geocoder with latitude and longitude from Place object
Note: This information was observed at this post. Repeated below.
Actually you can achieve this, you will just need to use the GeoCoder to do the lookup. Then simply use the Address object to get the data you need.
Here is some Java code to showcase the solution.
List<Address> addresses = null;
addresses = geocoder.getFromLocation(latitude, longitude,1);
if(addresses != null && addresses.size() > 0 ){
Address address = addresses.get(0);
// Thoroughfare seems to be the street name without numbers
String street = address.getThoroughfare();
}
I'm developing a android application that uses the user location to show a list of street name suggestions around their coordinates, since location retrieval is not going to be accurate enough, and in my application i need the best accurate position.
I tried a lot of approaches, tested google reverse geocoder, but it only gives me only one address, i tried google places api but it's not intended to return addresses, but places, what's not i'm lookin for, i tried findNearBy streets of geonames, but it only gives me street names, i need full data of the streets, like, city, state, country... i tried to use both geonames and google geocoder, getting a list of names, and converting each name into reverse geocoder request, but some street names are also available in another countries, i dont know how to specify a name and a latlng in geocoder request to filter results near specific coordinate.
I tried apis on server-side, which is a django-python server, the scenario is: the user sends their coordinate to server, which will use user location to request to another api's and format the result to the android, but didn't manage to found a good and fast solution.
I've seen a lot of some similar questions on SO but none had the answers I am looking for.
I was wondering as to whether it is possible to get the current location type based on the address. The implementation is that using GPS I will be able to get the address of the current location (similar to dropping pins on Maps and getting the address).
What I would like to know is whether based on the address, can I get the type of the location for example whether it is a movie theater, hospital, a restaurant, shopping mall, etc.
Has anyone tried to implement this?
Yes. You can use the Geocoding API to get the place_id. This is a unique identifer that can be used with other Google APIs, like the Places API. This gives more information (name, ratings, etc).
I have a form in which user will type his address but i want to create such widget for address so that whenever user types his address, then all similiar location will be listed in the suggestion box and user can select his location.
Similiar functionality i have seen in google map navigation application.
Can you please tell me how create such feature?
If you are talking about matching places for a street address, this should work:
use reverse geocoding to convert it into (latitude, longitude) pair, both Android itself and Google API provides this service;
use Google Places API to obtain nearby places using the pair of coordinates
I have a project which actually does the similar job, while due to some reasons it is not public, but I can assure you this way could work.
Hope it helps.