Am I hitting limits or is my code flaky?

65 views
Skip to first unread message

Mike Dolbow

unread,
Nov 18, 2011, 12:36:05 PM11/18/11
to google-map...@googlegroups.com
All:
I've got a few pages that I've developed in the past that don't get a lot of hit counts, maybe 100 a day at peak, 5-10 a day most of the time. When developing, I haven't had too many problems using the geocoder and reverse geocoder - an occasional timeout, but that's about it. Here's an example production page:
http://gis.mda.state.mn.us/food

With my latest project, I'm handling reverse geocodes both through marker drag and map click events. But even when using regular geocoding, it seems my status responses are flaky - sometimes it's quick and I get an address, other times it dives and I get an error returned. Here's my new page under development (you can see lots of design changes, but the basic geocoding stuff is the same):
http://gis.mda.state.mn.us/maps/territories.htm

To be clear, when I say "error", I mean something otther than google.maps.GeocoderStatus.OK. When I get something different, I handle the error by showing the result in the DOM text on the left hand panel. So, if you have time to help, I'm curious:
  1. Do you get any errors? Try an initial text geocode, then dragging or clicking to move the marker. It seems like the second one fails more frequently.
  2. How do I know if I'm up against limits? I wouldn't think I was even close.
  3. Do you see any errors or potential flakiness in my code? The uncompressed version is here: http://gis.mda.state.mn.us/maps/js/territories.js
Thanks in advance for your help.

Marcelo

unread,
Nov 18, 2011, 12:52:13 PM11/18/11
to Google Maps JavaScript API v3
On Nov 18, 10:36 am, Mike Dolbow <mike.dol...@state.mn.us> wrote:
>    1. Do you get any errors? Try an initial text geocode, then dragging or

>    clicking to move the marker. It seems like the second one fails more
>    frequently.


No, I dragged the marker to about 10 different locations and no
errors.

>    2. How do I know if I'm up against limits? I wouldn't think I was even
>    close.

The status would be google.maps.GeocoderStatus.OVER_QUERY_LIMIT


>    3. Do you see any errors or potential flakiness in my code? The


>    uncompressed version is here:
>    http://gis.mda.state.mn.us/maps/js/territories.js

In the function placeMarker(), you are adding a new event handler, (or
listener), every time the marker is moved. You should add only one
listener, when the marker is created.

--
Marcelo - http://maps.forum.nu
--

Mike Dolbow

unread,
Nov 21, 2011, 9:44:17 AM11/21/11
to google-map...@googlegroups.com
Glad you aren't getting the errors I'm getting. I've only occasionally gotten an over query limit status. Recently I've just been getting a status of "ERROR" when it fails.

Thanks for trying to help out with the code. As I understand it, I'm only adding a listener when the marker is created or placed. The listener needs to be triggered by a drag (end). I've verified this by adding an alert:

//create a marker and listener
function placeMarker(location){
    marker.setMap(null);
    marker.setMap(map);
    marker.setPosition(location);
    marker.setDraggable(true);

    //listener for drag
    alert("let's add a listener!");
    google.maps.event.addListener(marker, 'dragend', function(event){
    clearResults();
    var mPoint = marker.getPosition();
        map.panTo(mPoint);
        reverGcode(mPoint);
    });
}

The alert only kicks off when the marker is created, not when it's dragged. But perhaps I'm missing something you were trying to convey?
Thanks,
mike


Mike Dolbow

unread,
Nov 21, 2011, 9:53:15 AM11/21/11
to google-map...@googlegroups.com
Crud, now I think I see what you mean. It's not that the listener gets created every time the marker is dragged - it's that I call the "placemarker" function (which creates the listener) even if a marker has already been created, right? And there's too many ways to call that function.

I need to clean up my sloppy Javascript. Any other tips?
mike

Mike Dolbow

unread,
Nov 23, 2011, 10:38:06 AM11/23/11
to google-map...@googlegroups.com
OK, I've made some adjustments and I think it's just a matter of how my pages are communicating with Google's geocoding services. Typically the error is just "ERROR", which according to the API documentation, is just "There was a problem contacting the Google servers." This seems to happen the most when working from my local host or my development server. Has anyone else noticed this kind of thing coming up consistently? It seems like the Google servers have been a bit hard to reach lately - I notice directions not working as quickly as usual.

Anyway, thanks in advance for any tips.
Reply all
Reply to author
Forward
0 new messages