I think in this block of code :
var marker = new google.maps.Marker({
position: location,
map: map,
title: this.LocationName
});
the "map" var you declared back in the initiation is may not be
available in this scope. You can either declare "map" as a global or
put it into an object literal.
I wrote some example code
http://www.joelee.me.uk/sampleCode/2010/googleMapsV3markersClearExample.html
Two things to note :
- "var mapStuff =" near the top is the code declaring the mapStuff as
an object literal
- "function addPubToMap" sees the code passing the mapStuff.theMap
into the parameter map parameter of the marker object
Hope that helps
On Aug 20, 11:51 pm, Morten <[email protected]> wrote:
> Upon page load I load and show a Google Map:
>
> var latlng = new google.maps.LatLng(lat, lng);
> var myOptions = {
> zoom: 8,
> center: latlng,
> mapTypeId: google.maps.MapTypeId.ROADMAP
>
> };
>
> var map = new google.maps.Map(document.getElementById("map_canvas"),
> myOptions);
>
> From within a select box's onchange handler I get location json and
> would like to add these locations to the map.
>
> How can I reference the map without the re-initializing part?
>
> Something like:
> var map = google.maps.Map(document.getElementById("map_canvas"));
> $.each(locationCollection, function (i) {
>
> var location = new google.maps.LatLng(this.LocationLat,
> this.LocationLong);
> var marker = new google.maps.Marker({
> position: location,
> map: map,
> title: this.LocationName
> });
>
> });
--
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.