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
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.
I would like to know what is the best way to get the distance between 2 (zip code) or postal code in Canada. I have seen post about MySQL doing so with US zip code.
Or I guess that I could probably translate a zip code to coordinates and then triangulate distances? If anyone can share tips on this I would apreciate!
Im working with Angular JS and Node JS but I could do with PHP as well.
An Api should be free and be able to handle large ammount of querys.
Thank You
Google Maps API can do it, by setting origin and destination on the distancematrix API.
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=M4C4Y7&destinations=H1A0A2
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 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.
I'm trying to figure out how to get the location of someone filling out a web form on my site. I just want to get it down to a state level for US and Country for international(although state or equivalent is fine international too). I just don't want the user to have to select from a super long list or fill out a field. So ideally something like a hidden field that could have javascript or php pass the info to it.
Any ideas?
You can try; http://www.w3schools.com/html/html5_geolocation.asp
And using Google API:
http://maps.googleapis.com/maps/api/staticmap?zoom=10&size=400x400&maptype=roadmap&markers=color:red%7Ccolor:red%7Clabel:C%7Cxx.xxxxxxx,xx.xxxxxxx&sensor=false
Using PHP or Javascript to replace the "xx.xxxxxxx"'s will give you a map of the users location.
You can probably use Google API to determine the users State, etc - as you mentioned. But I don't think you will be baby fed on this one.
You could try to figure out their location using their IP address. However, this is far from reliable. Unfortunately, if you need this data to be accurate, you're going to have to get them to give you their location.