Google Place API city search by coordinates - google-maps

I'm trying to access cities from the google place API. I want to be able to search with coordinates and have it return a city. My goal is for a user to be able to enter in a city and a photo shows up. So after getting the city, I will use the photo reference to get the image.
This is my request
https://maps.googleapis.com/maps/api/place/search/json?location=35.4107,80.8429&radius=100&sensor=true&key=API_KEY
the coordinates entered is a City in North Carolina. However, it does not return a city within North Carolina at all. All I am looking to do is use coordinates inside my request and have it return the city the coordinates are in. I'm relatively new to development, if I have been unclear in any way please point it out so that I may correct myself. Thanks!

I believe reverse geocoding is more suitable for your task than Places API. Places API is designed to search businesses and POIs at first place, localities shouldn't be among the results.
With reverse geocoding you can specify a coordinate and type of result you are looking for. For example, to search the city use the following request
https://maps.googleapis.com/maps/api/geocode/json?latlng=35.4107%2C-80.8429&result_type=locality&key=YOUR_API_KEY
This will return the "Huntersville, NC 28078, USA"

Related

Google Directions API Travel Mode TRANSIT not working for street_address

Apologies if I'm writing obvious question.
Though I cannot find document anywhere online so I have decided to ask here.
Is it the case that transit mode in Goolge Directions API is only valid if origin and destination are point of interest?
If either or both address is type street_address, I am not able to receive response containing travel_mode=TRANSIT.
What I want to achieve from the API is a result like Google Map, where it outputs optimistic route between the origin and destination; consisting waypoint(s) of public transport in the middle of the trip.
E.g. Point of Interest to Point of Interest returns fine
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=Chatswood%20station&mode=transit&transit_mode=rail&key=[key]
E.g. Point of Interest to street_address returns ZERO_RESULTS
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue&mode=transit&key=[key]
E.g. Inserting "Wynyard Station" as origin and "441 Victoria Avenue" as destination in Google Map returns route including both transit and walk to the destination.
The issue with your request is that you are using incomplete address string '441 Victoria Avenue'. This is really ambiguous query. If you check it in Geocoder tool, you will see that this string is resolved to '441 Victoria Ave, Forrest City, AR 72335, USA'
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D441%2520Victoria%2520Avenue
So, you try to find a transit (train) directions between one place in Australia and another one in the USA.
ZERO_RESULTS is expected in this case. You should specify a more precise address string or use autocomplete to search transit directions using place IDs.
https://developers.google.com/maps/faq#geocoder_queryformat
https://developers.google.com/maps/documentation/geocoding/best-practices
For example, using '441 Victoria Avenue, Sydney' I can get transit directions
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train&key=YOUR_API_KEY
You can check this in Directions calculator tool:
https://directionsdebug.firebaseapp.com/?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train
Hope it helps!

With the Google API is there anyway to get all of the cities in a state, and all of the towns in a city?

I am trying to build an application where a user can "drill-down" so to speak to find a location. So if they click on "US" it should show all of the states, and if they click a state it should show all of the cities. I have looked at the Google Places API, and I'm not exactly sure what the best method is. I thought about using bounds but I feared it would not be accurate because bounds works off of a rectangle. Not the actual city or state.
There is no any Google Maps API that can return a list of cities in the state. The Google APIs does not work this way, they are not like a database search.
You can try a Places API autocomplete, but this API returns up to 5 suggestions when you are typing a text. You cannot define a strict filter by city or state, you can only bias result to certain view port.

Google Maps: Is there a way to find out whether a city has a detailed map (not StreetView)?

I have a point on a map. The point belongs to a city which doesn't have a detailed view with all the streets and buildings yet. But I hope Google will cover this city some time in the future. So I have to display map in a satellite view for now but it would be perfect if the map started to display in a standard view as soon as Google covers the city.
Is it possible to determine programmatically whether city has a detailed view with streets and buildings on Google Maps?
I solved my problem using reverse geocoding for a given point on a map. If result has a ROOFTOP location_type parameter, that means that the map contains a building at that point. Otherwise there are no buildings.

Google reverse geocoding - how to snap to nearest full postcode

I am using Google's reverse geocoding functionality with the maps api v3 to retrieve postal addresses for latitude longitude (when dragging a marker around a map).
This is a UK application only, and part of the system requires a full, or near full, postcode to process correctly. However the reverse geocoder regularly returns just the part of the postcode - for example "GU3", even when the actual address returned appears to be complete - for example including street and house number.
Is there anyway, preferably google but otherwise if not, of 'snapping' the address to the nearest full postcode?
I'm aware similar functionality exists for snapping to the nearest panorama view, but there appears to be no equivalent for postcode.
The UK post code database is available for download from the Ordnance Survey open data
www.ordnancesurvey.co.uk/opendata
Alternatively you can use a service like uk-postcode.com to return the closest post codes to a location
See the example at https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse
Try a UK location like 51.436951, 0.058112.
The results include an address_component of postal_code, "SE9 3AG".
It may be necessary to geocode the address you're given and then reverse-geocode the results in order to get the postcode. But it is possible.

How to look up ZIP/Postal Code by City using Google Maps API?

How can I extract a Postal Code or ZIP of a place by giving Google Maps a city on the map?
Basically I'm looking for a free verification service for checking completed addresses for accurate details.
I seem to remember the maps API can somehow provide a geographical point when given an address. Now I'm searching for a slightly reversed situation in order to validate the postal code typed in with a city.
You need to Geocode the address to get best match coordinates
and then Reverse Geocode the coordinates to compare zip.