Geocoding markers shows error when creating 11 or more | moderntymes | 7/13/10 5:43 AM | I'm trying to create a map with approximately 40 markers. Each marker
is geocoded and has an event handler for 'clicked' that redirects to a new page. I've pretty much used the geocoding code straight from the Google API v3 site, but the code fails if I add more than 10 markers. On the 11th, I get a Javascript error. If I try to show more than 11, then all the markers disappear. I receive a rather useless (to me at least) error message: '0' is null or not an object. If I take out the event handler, the problem remains so it seems to be connected to the geocoding. I think it has something to do with these lines: geocoder13.geocode( { 'address': '6059 S Seneca,Wichita,KS,67217'}, function(results, status) { var marker13 = new google.maps.Marker({ map: map, position: results[0].geometry.location, title:"Cox Farm" }); }); In particular, if I remove the stuff after function(results, status) { up to the next }, I don't get an error. Of course I also don't get any markers! I tried with each geocoding occurence listed separately, which you can see here: http://cornmaze.moderntymes.com/map.htm I also tried making a function to do the geocoding here: http://cornmaze.moderntymes.com/map_testgc.htm Results are the same either way. |
Re: Geocoding markers shows error when creating 11 or more | geoco...@gmail.com | 7/13/10 6:19 AM | The general advice is not to geocode addresses everytime your page
loads. Geocode them once, offline, then use the resulting coordinates to display the markers. Geocoding the addresses every time wastes google's resources, so they have implemented rate limits and quotas. You should only geocode addresses you don't know in advance (like user input) on the fly. -- Larry |
Re: Geocoding markers shows error when creating 11 or more | moderntymes | 7/13/10 6:46 AM | Certainly that's good advice, but these locations are actually dynamic
(or will be in the final version). The locations will be coming from a frequently changing database, so I'll need to be doing the geocoding. I think there's a problem with the programming though, and I think it is related to the Javascript closure. On Jul 13, 9:19 am, "geocode...@gmail.com" <geocode...@gmail.com> wrote: > -- Larry- Hide quoted text - > > - Show quoted text - |
Re: Geocoding markers shows error when creating 11 or more | geoco...@gmail.com | 7/13/10 7:27 AM | On Jul 13, 6:46 am, moderntymes <doug-goo...@moderntymes.com> wrote:Sounds to me like you need to implement your code to handle error conditions better. -- Larry > > - Show quoted text -- Hide quoted text - |
Re: Geocoding markers shows error when creating 11 or more | geoco...@gmail.com | 7/13/10 7:48 AM | On Jul 13, 7:27 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote: > On Jul 13, 6:46 am, moderntymes <doug-goo...@moderntymes.com> wrote:and add a createMarker function so you get function closure: http://www.geocodezip.com/cornmaze_moderntymes_com_map_testgcA.html Note that even with those few locations I get an OVER_QUERY_LIMIT error for one of those points. You will need to rethink your design. |
Re: Geocoding markers shows error when creating 11 or more | moderntymes | 7/13/10 8:30 AM | I have no idea why there would be OVER_QUERY_LIMIT error, but isn't
that on a per client basis anyway? I certainly haven't made 2500 geolocation requests today. That seems very odd. I tried to keep the code design as simple as possible. I will try creating a createMarker function to get function closure, which could very well be my problem. I understand I need to "rethink my design", which is why I was posting here.The createMarker function will hopefully help, and thanks for the code sample! On Jul 13, 10:48 am, "geocode...@gmail.com" <geocode...@gmail.com> |
Re: Geocoding markers shows error when creating 11 or more | Rossko | 7/13/10 8:50 AM | > I have no idea why there would be OVER_QUERY_LIMIT error, but isn'tNot odd at all. 2500/day is one every 35 seconds. Google do allow you to have small bursts, but they do also apply a rate limit which your method is clearly breaking. You need to throttle your requests. Your map is going to load very slowly if you geocode every time someone views it. Geocode your data at point of entry to the database ; it matters not if it changes daily. Not only does it prevent your application from hogging resources shared by other people, but your own map will perform many times faster. |
Re: Geocoding markers shows error when creating 11 or more | moderntymes | 7/13/10 3:44 PM | If there is throttling, which would certainly explain this, Google
should really say so in their API. If it weren't for their rate limiting, seems like it would load plenty fast since the 10 that work ok come up quite fast. Forty doesn't seem like so many to me, considering I've seen examples where there are 100s or even thousands of markers. I understand they must not be geolocating for those, but still... I read and re-read the section in the API regarding geolocation (again just now) and didn't see anything about a rate limit, other than the 2500/day limit. I appreciate your info and quick responses, to make up for what the online references lacked! |
Re: Geocoding markers shows error when creating 11 or more | geoco...@gmail.com | 7/13/10 7:08 PM | On Jul 13, 3:44 pm, moderntymes <doug-goo...@moderntymes.com> wrote:They aren't geocoding, they are using latitude and longitude directly without using any additional resources from google other than the API javascript and the map tiles. Geocoding is a shared "free" resource. You are trying to hog it. The rate limit prevents people from doing that. -- Larry > > perform many times faster.- Hide quoted text - |
Re: Geocoding markers shows error when creating 11 or more | Rossko | 7/14/10 1:29 AM | > I read and re-read the section in the API regarding geolocation (againWhat it does say is "The Google Maps API provides a geocoder class for geocoding addresses dynamically from user input." They're not expecting users to type so fast. |