google maps pan to

对着背影说爱祢 提交于 2019-12-04 07:38:36

@onemach is correct.

1. You have to declare the map as a global variable at the beginning of javascript. Just do a var map; declaration immediately after <script type="text/javascript"> tag.

2. And at the same time your map initialization should be changed to

map = new google.maps.Map(document.getElementById("map"), myOptions); // without the 'var'

3. Your calling clickroute() onClick of <li> without parameters. So change the definition of clickroute() like this :

function clickroute() { //just omit the 'lati' and 'long'
    var latLng = new google.maps.LatLng(51.433373, -0.712251);
    map.panTo(latLng);
}

Now clicking on the test <li> your map will move to point (51.433373, -0.712251)

clickroute(map); is incompatible with the definition

function clickroute(lati, long) {
    var latLng = new google.maps.LatLng(51.433373, -0.712251);
    map.panTo(latLng);
}

I guess what you want it

function clickroute(map) {
    var latLng = new google.maps.LatLng(51.433373, -0.712251);
    map.panTo(latLng);
}

UPDATE:

I am confused what exactly do you want.

onclick=clickroute() does not pass any arguments to the function.

Also there is no global map in clickroute.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!