I want to retrieve the nearest location to a latitude and longitude.
If I perform a get with the following url
https://maps.googleapis.com/maps/api/place/search/xml?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=MY_KEY
I am expecting it to return a JSON array.
However, I get an Access Denied result. I generated my key from the Google console.
Please let me know what I might be doing wrong.
For retrieving the current location of device you can go-through this answer and this answer.
Then get places near your location using Google's Place API and you can also refer this blog.
Related
I am using Mapbox GL JS to show certain location marked on the map.
I need to set location through JavaScript code and I don't know the lat and long coordinates, I only have an address in string form (example: "address, city, country" or some similar format).
I have searched a lot on the internet, but the only way that I have found for doing this in Mapbox GL JS is by using Geocoder input control, but I don't want to input location through it, I want to set Address through code and then have it marked on map when the map loads.
Is it possible to do this in Mapbox GL without knowing lat and long coordinates? How can I do that?
Thanks in advance! Best regards!
You can use the Mapbox Geocoding API without the Geocoder control. You have to compose your url (and encode it).
Always consider you could get more than one result in the featureCollection response depending your params, so finally you have to refine the results with some of the attributes allowed such as proximity and limit. At the beginning is a bit of try and error task, but after some practice it's quite accurate.
Here you have an example url for the address 123 Main St Boston MA 02111, filtering the results in United States only.
https://api.mapbox.com/geocoding/v5/mapbox.places/123%20Main%20St%20Boston%20MA.json?country=US&access_token=pk.eyJ1IjoianNjYXN0cm8iLCJhIjoiY2s2YzB6Z25kMDVhejNrbXNpcmtjNGtpbiJ9.28ynPf1Y5Q8EyB_moOHylw
This will return 5 streets in the Massachusetts state.
I recommend you to read the documentation in forward geocoding, and also the section on address geocoding format to compose properly the url.
Google map post code doesn't show exact address using Google maps API! For example if I search a nw107ns it shows park royal as formated_address which is a big place while it should show Middlesex center hospital.
Am using Google map API with restrictions to UK only.
Your answers are appreciated!!!
If you are using Geocoding API, please note that this API meant to convert complete addresses to lat-lng coordinates. Providing only the postal code and the country will give you the details of the postal code NW10 7NS. To get the address of Middlesex center hospital, you must at least include the name of the establishment on your API request to make it more specific.
Like this:
https://maps.googleapis.com/maps/api/geocode/json?address=Middlesex%20center%20hospital&components=country%3AGB®ion=GB&key=YOUR_API_KEY
When using Geocoding API, make sure to adhere to Geocoding Best Practices.
If you are using autocomplete, generally Place autocomplete will return a list of places matching the user's input. If you input NW10 7NS, the autocomplete will return the the place of type postal code since this matches the user's input. If ever you filter the results by type(e.g establishment), the autocomplete will only return places with names or addresses that matched the users input. In the case of NW10 7NS, the API will not return anything since there's no place of type establishment named "NW10 7NS".
Here's a sample Place Autocomplete implementation you can refer to: https://jsfiddle.net/tzgq6kva/
I'm doing restaurant search engine for my project and I'm stucked with current location.. I can get my lat and lng from navigator (geolocation HTML5).
The point is, that I need postal code, not lat and lng. The only idea I had was to get that lat and lng and connect with postal code using some API.
I've found something like this:
http://api.geonames.org/findNearbyPostalCodes?lat=52.198500&lng=-2.219200&maxRows=1&username=demo
How can I refer to the post code from that API? The best with javascript?
Have you got maybe other ideas? I've got one button and after clicking on that button, I want postcode from my location in text input.
Would you be able to make an API to the following Service and convert the data?
Please look at the following and let me know if you need help Consuming the API..
https://docs.mapbox.com/api/search/#geocoding
Greetings i was searching for hours and I haven't found anything remotely close to this.
I am trying to use Distance Matrix API, However as an input the api needs the Origin Address aka Name and Destination as well. But i can only provide Origin's Lat/Lng and Destination's Lat/Lng from which i get them using my own markers.
Is it possible to get the place's Name and Address from Lat/Lng of the given origin?
Or Am i in whole wrong path to achieve this? any suggestion would be appreciated. thank you.
For your information. DistanceMatric Api works not only with string addresses it also works with lat/lng, place_id as well.
Go through below doc
https://developers.google.com/maps/documentation/distance-matrix/intro
So, no need to convert your lat,lng to string addresses.(otherwise simply api hits will increase)
If you want to see result. Check below api.
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=40.6655101,-73.89188969999998&destinations=40.6905615%2C-73.9976592&key=[API_KEY]
Note: Replace API_KEY with your api key
You can use the latitude/longitude coordinates for origin and destination parameters. Its in the documentation https://developers.google.com/maps/documentation/distance-matrix/intro
But if you really want to get the address from latlng you can reverse geocode it like this:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
here is the link to the documentation for your reference
https://developers.google.com/maps/documentation/geocoding/start
I am new to angularJS, I use the ngAutocomplete to get the locations from google service. It gives me the latitude and longitude whenever I select a location.
Now, I want to get the area and location name from selected latitude and longitude by reverse geocoding service.
I want to use the googple javascript API in ngAutocomplete module, so if user selects a location then It will return the area and location name too.
Thnanks
You are may be asking about Reverse Geocoding to get the detail information of location.
You can get the enough information about the Reverse Geocoding from
https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
Thanks.