Toggle inside toggle for Google Maps -
i've made google map show location @ beginning 1 marker. there have possibility switch location. show new location 1 marker.
aside location switching it's possible select sub locations each of 2 main locations.
i thought making 2 vars ( each location 1) best thing [example]:
var locationsberlin = [ ['berlin 1', 52.519433,13.406746, 1], ['berlin 2', 52.522606,13.40366, 2], ['berlin 3', 52.52113,13.409411, 3], ['berlin 4', 52.517043,13.402394, 4], ['berlin 5', 52.51703,13.412801, 5], ['berlin 6', 52.525086,13.399798, 6], ['berlin 7', 52.525151,13.410741, 7] ];
this how select "main" location.
markermain = new google.maps.marker({ position: new google.maps.latlng(locationsberlin[0][1], locationsberlin[0][2]), map: map, icon: custompin });
the rest of array sublocations. want user able press link , show rest of locations in var (the amount of locations dynamic).
so tried make function called after clicking toggle link.
function sublocationberlin(){ alert("berlin sub"); (i = 1; < locationsberlin.length; i++) { marker = new google.maps.marker({ position: new google.maps.latlng(locationsberlin[i][1], locationsberlin[i][2]), map: map }); markers.push(marker); } }
but i'm stuck. reason it's not adding markers map , don't know what's wrong.
over here can find fiddle: http://jsfiddle.net/gvmsx/3/
your map variable (the 1 initialized , displaying map) local initialize function:
var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions);
remove "var" in front of initialize global version.
note javascript arrays 0 based, missing first marker when initialize 1 in loops
function sublocationberlin(){ console.log('berlin sub called'); (i = 1; < locationsberlin.length; i++) { marker = new google.maps.marker({ position: new google.maps.latlng(locationsberlin[i][1], locationsberlin[i][2]), map: map }); markers.push(marker); console.log(marker); } }
Comments
Post a Comment