looking for jquery solution to map_canvas issue in Google maps -
apparently google map displayed in div if called 'map_canvas', causing me bit of problem. without going detail, app rails based, different pages being rendered, , on 1 page want call initialize_google_maps() , on other page want call initialize_google_maps2()
but how can distinguish between 2 different pages? ideas? example using code below, , in page map_canvas2 thought being smart having map_canvas nested, like:
<div id="map_canvas2"> <div id="map_canvas"></div> </div>
but when both functions called - initialize_google_maps(); , initialize_google_maps2(); code have is:
if ($("#map_canvas").length) { initialize_google_maps(); } if ($("#map_canvas2").length) { initialize_google_maps2(); }
any ideas how distinguish between them? thanks.
and initialize function goes (getelementbyid must called 'map_canvas', i've read):
function initialize_google_maps() { console.log('map canvas again'); var currentlatlng = new google.maps.latlng(map_latitude, map_longitude); var zoom = 10; var myoptions = { zoom: zoom, center: currentlatlng, maptypeid: google.maps.maptypeid.roadmap, // roadmap, satellite, hybrid streetviewcontrol: false }; map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); console.log("definition of map"); var marker = new google.maps.marker({map: map, position: currentlatlng, icon:{oppacity:0}}); // map.setcenter(currentlatlng); // map.setzoom(zoom); console.log("definition of marker"); var circle = new google.maps.circle({ map: map, fillopacity: 0, strokeweight: 2, strokeopacity: 0.7, radius: 10000, }); console.log("definition of circle"); circle.bindto('center', marker, 'position'); console.log("circle2"); }
if @ line below says ("map_canvas") can change whatever name need. make sure in div matches changed in line.
map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); console.log("definition of map");
Comments
Post a Comment