Wouter
unread,Nov 22, 2010, 5:45:17 AM11/22/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Maps JavaScript API v3
Hi,
In my form-generator i want to use google maps so users can fill in
locations. I would like my generator to be able to support an
unlimited number of maps. The form-template generates an inputfield
(hidden) and a canvas-div for each map. My idea is to use javascript
to copy the latlang from a clickevent in the corresponding inputfield.
My html:
<label for='fieldname'>location</label>
<input class='hidden' id='fieldname' type='text' name='fieldname'
size='10' value='' readonly='readonly' />
<div id="fieldname_gmap" class="gmapform"></div>
My javascript:
var map = new Array();
var marker;
function init_gmap() {
//init maps
var mapzz = getElementsByClassName("gmapform", document, "DIV");
if ( mapzz ) {
for ( i=0; i<mapzz.length;i++ ) {
var loc =
document.getElementById(mapzz[i].id.replace("_gmap", "")).value;
if ( loc == "" ) { loc = "0,0"; }
loc = loc.split(",");
var latlng = new google.maps.LatLng(loc[0],loc[1]);
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map[i] = new google.maps.Map(mapzz[i], myOptions);
google.maps.event.addListener(map[i], 'click',
function(event) { alert("here i would like to alert the mapid that
generated the event");});
}
}
}
I'm probable missing something very elementary here, but I cannot
figure out how to know the id of the canvas that triggered the
clickevent. Seems like event only has latlng, nothing else?
Any help on this is greatly appreciated!