I have a google map with multiple markers.I done that using google map Geocoder with the help of this link Geocoder usage .But,it was limited to some markers only.After the limit it is showing the error as queryLimit.Is there any way to show the multiple markers on the map without any limit.It can be other than Geocoder too.Thanks
You should never use a webservice or API to get the locations every time you want to show the markers. What you need to do is store the latitude and longitude somewhere. Preferably the same place you are storing the address information. Then just use those latitudes and longitudes to generate the markers with no need to worry about query limits.
The reason you are exceeding the query limit is that you are doing the queries too fast. If you have a period between each query you can do a lot more before hitting the querying cap, but this is not a solution. You should always save the location instead of querying every time :)
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'm doing a little project which heavily relies on locations and my question here is...
Is it possible to use the google map API to get cities within a certain radius from a location so that I can reduce the number of times I have to query on my database before I get the results I want?
I have previously done a radius search by using the locations stored on my database and I'm thinking that if it is not possible to get the cities within radius with just the use of the google map API,
My alternative solution would be to get all locations (stored in my database) within a certain radius by filtering them via lat and lng and get all distinct localities of the returned locations.
However, results can be inaccurate. Because there can be datas stored up in my database that might not show up if it is not within radius from the location specified during radius search, despite being in the same city/locality, which is actually the filter that I want.
I'm using Mapbox in a web app. I have functionality where a user inputs a zipcode and it should display on the map then do some other stuff with the data. All I'm trying to do right now is convert the zipcode to latitude and longitude to display the marker on the map and log the coordinates. Is there a way to do this in the Mapbox API? If so I can't seem to find it. If not, is there another easy way to do this?
Mapbox has it's own geocoding API in public beta:
Geocoding requests are queries composed of location text or lat/lon coordinates that can be used to find corresponding place data. A geocoding request includes a geocoding {index} in requests which specifies the dataset to use to find place data.
https://www.mapbox.com/developers/api/geocoding/
I am using Geocoder callback function for getting latitude and longitude value which is asynchronous.
This works great for the 1st 10 items. I will see a markers on the map as well as those 10 listed on my sidebar. However, the 11th item and beyond will not display anything. I am querying our internal database based on parameters set which often will produce 30+ rows returned in the database table which I am looping through.
Is there any way to display more than 10 addresses on google map. or is there any need to purchase any license for get additional API for geocoder .
Thanks in advance !
The Google Geocoding services are rate limited and subject to quotas (to prevent abuse), the (paid) Google Maps API for Business, does have higher limits. The usual suggestion is to geocode the loctions offline, store the coordinates in your database, then use those coordinates to display the markers.
If you can't store the locations in your database, you need to check the return value in the geocoder and delay when it returns over query limit errors. There are examples of doing that both here in SO and in the Google Maps API v3 group.
I have an app that saves google map markers, I basically save the lat lng coordinates/vriables in an array, then I save it in my mongodb. When I reload those markers, I loop in the array and create markers from the saved lat lng variable.
My problem is that when I saved my markers the first time, a lat was called Pa and a lng Oa, then 1 month ago, I save markers, and then try to load them, but my loop doesn't recognize the lat lng variables, they were changed to Sa, Ta. So I changed my client code to pull variables of Sa, Ta instead, no big deal.
Today, I save another array of marker, try to load it, and it doesn't work, again their native google api variable name are changed to lat Ua and lng Va ... My client code doesn't work for any new saved marker.
I'm obviously not saving markers the "google" way, what am I doing wrong?
Thank you
You should not rely on the variable names of minimized code. Call them "lat" and "lon" or something like that. The internal names such as Pa are potentially lost on each recompilation. In particular, they will likely change when Google fixes a bug or releases a new version of the API.
So don't just blindly encode the marker objects. Convert them to a stable representation that you control yourself (and not the automatic code compiler of Google maintains and changes at will).
Since the API seems to be changing every once in a while you might want to decouple your implementation from it. Store lat and lon however you want and then write adapter that maps that data to Google API suitable and back on save.
mongodb is unsuitable for storing lat/lng as there is no arbitrary precision or decimal data type in BSON. mongo data types