On 1 February 2011 21:18, Eugene <[email protected]> wrote: > Please, help for beginner: > I have Google map in HTML page, which declared in HTML as DIV-element > (as it made in example) > > <div id="map_canvas" style="width:610px;height:470px;border:1px > solid;"> > > In another part of this HTML-page I want to request to this Map and > set marker on it. > In JavaScript I write > > document.getElementById("map_canvas") > > but, sure, I'm getting the object "HTMLDivElement". > So, is there any way to get access to existed map on page ?
I suggest following the examples, particularly http://code.google.com/apis/maps/documentation/javascript/v2/examples/marker-simple.html That one uses a loop to create 10 random locations and place a marker at each of them. The relevant lines for a single marker are var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(..., ...), ...); // needs lat, lng, zoom for map var latlng = new GLatLng(..., ...); // needs lat, lng for marker map.addOverlay(new GMarker(latlng)); That is, document.getElementById("map_canvas") is indeed an div-element object. But the "new GMap2(...)" uses that div for the map, and you get hold of the map by assigning it to a variable, "var map" in this case. -- You received this message because you are subscribed to the Google Groups "Google Maps API V2" 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-api?hl=en.
