javascript - Map not showing anchor with if else -
i made 2 maps on same webpage suppose show 1 map @ time. (eg. if location show map1, if location b show map2. changing maps work fine. problem have right anchor appears in 1 map. please help.
my javascript
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> function initialize() { var mylatlng = new google.maps.latlng(4.584007, 101.090027); var mapoptions = { zoom: 16, center: mylatlng, maptypeid: google.maps.maptypeid.roadmap } var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); var mylatlng1 = new google.maps.latlng(3.040517, 101.704167); var mapprop2 = { center: mylatlng1, zoom: 16, maptypeid: google.maps.maptypeid.roadmap }; var map2 = new google.maps.map(document.getelementbyid("googlemap"), mapprop2); var marker = new google.maps.marker({ position: mylatlng, map: map, title: 'location' }); var marker1 = new google.maps.marker({ position: mylatlng1, map: map2, title: 'location' }); } google.maps.event.adddomlistener(window, 'load', initialize); </script> <script> var originalnavclasses; function togglenav() { var elem = document.getelementbyid('navigation_list'); var classes = elem.classname; if (originalnavclasses === undefined) { originalnavclasses = classes; } elem.classname = /expanded/.test(classes) ? originalnavclasses : originalnavclasses + ' expanded'; } </script>
my if.. else statement
%if request.querystring("location") = "a" %> <a href="geo:http://maps.google.com/?q=3.040517,101.704167,15z"><img src="img/button_directions.png" border="0" /></a> <%else %> <a href="geo:http://maps.google.com/?q=4.584007,101.090027,15z"><img src="img/button_directions.png" border="0" /></a> <%end if%>
as show 1 map @ time, should avoid having 2 maps instances, pretty heavy , can lead kind of confusion. use 1 instance changing it's options when required. can change parameter of map instance after initialization.
right see :
var mylatlng = new google.maps.latlng(4.584007, 101.090027); var mylatlng1 = new google.maps.latlng(3.040517, 101.704167); var mapoptions = { zoom: 16, center: mylatlng, maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); var marker = new google.maps.marker({ position: mylatlng, title: 'location' }); // can set position of marker , center of map function changelocation(somecondition){ if(somecondition){ marker.setposition(mylatlng1); map.setcenter(mylatlng1); }else{ marker.setposition(mylatlng); map.setcenter(mylatlng); } }
if wanted behavior remember 2 different map statuses can store them
var mappreviousstatus = { center: map.getcenter(), zoom: map.getzoom(), maptypeid : map.getmaptypeid() // other parameter must remember };
working way bit more work more efficient.
Comments
Post a Comment