Okay, shortly after posting this I found a dirty way to get the
information I needed using a setInterval and getting the location of
the marker itself every 500 milliseconds, as the user moves it.  It
gives plenty of time to update the hidden form fields and save the
information.

There were a couple of problems with this actually, as far as I could
tell.

#1 - As far as I know, using an event on the marker itself will not
return a LatLng.  I had the same code in place except used the map to
give me the LatLng and it worked perfectly.  When I switched it to the
marker, it didn't return a LatLng.  Any example I've ever seen of
getting a LatLng from an event in V3 has been from map, so it makes
sense, I guess.

#2 - Even if that did work, in theory the marker's LatLng is updated
AFTER the callback function so the numbers returned would be the old
position of it, anyway.  So if you used the event listener and it
fired, you would think the next logical step would be
marker.getPosition() and get the position that way, but the position
technically hadn't updated.  I wrestled with this method for a while.

Considering I've found several problems with my (and a seemingly
simple) methodology, my advice is that if you stumble on this and
you're trying to do the same thing I did (return lat long into a form
to save it into a database), use setInterval in the initialize
function and have it call a function looking like this:

setInterval("updateMarker();", 500);

function updateMarker()
        {
          newPosition = marker.getPosition();
          var newLat = newPosition.lat();
          var newLong = newPosition.lng();

          // Update the appropriate form fields with new variables
        }

I'm not sure it's the best way to do it, but at least it works.


On Sep 25, 5:29 pm, Rossko <[email protected]> wrote:
> > google.maps.event.addListener(marker, 'mouseup', function(event) {
> >     updateLatLong(event.latLng);
> >   });
>
> I would expect that to pass an object of type LatLng to your 
> functionhttp://code.google.com/apis/maps/documentation/javascript/reference.h...
>
> >       var newLocation = new google.maps.LatLng(location);
>
> The LatLng constructor expects to be given two numbers, not one
> object.
> Just use the passed LatLng object directly.
>        alert( location.toString() );

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to