简体   繁体   English

Google Map:如何重定向到地图上的其他点?

[英]Google Map: How to redirect to other points in the map?

I have a google map and a select. 我有一个谷歌地图和选择。 I have to give the user to the select different places in the select and redirect him to that place in the map. 我必须给用户选择中选择的不同位置,然后将其重定向到地图中的该位置。

So when a user select place A he can be redirected to San Francisco for example. 因此,当用户选择地点A时,他可以例如重定向到旧金山。 And when select place B he can be redirected to Los Angeles. 当选择地点B时,他可以被重定向到洛杉矶。

Do you know how can i obtain this? 你知道我怎么能得到这个吗?

Here i made a basic example, there is the map and the selector: 在这里我做了一个基本的例子,有地图和选择器:

http://jsbin.com/iGOmEXeP/2/edit http://jsbin.com/iGOmEXeP/2/edit

Here i made my shy attempt to obtain what i needed, that as you see is not working: 在这里,我很害羞地尝试获取所需的东西,如您所见,这是行不通的:

http://jsbin.com/iGOmEXeP/3/edit http://jsbin.com/iGOmEXeP/3/edit

Hope that somebody can helps me! 希望有人能帮助我! Thank you! 谢谢!

EDIT: 编辑:

I have obtained something here: http://jsbin.com/iGOmEXeP/5/edit 我在这里获得了一些东西: http : //jsbin.com/iGOmEXeP/5/edit

Anyway if you have something better, or a way to improve it, i will consider as correct answer. 无论如何,如果您有更好的东西或改进它的方法,我将认为这是正确的答案。

You should read up on the documentation here. 您应该在这里阅读文档。

https://developers.google.com/maps/documentation/javascript/reference#Map https://developers.google.com/maps/documentation/javascript/reference#Map

What you are looking for is either the setCenter() or panTo() methods. 您正在寻找的是setCenter()panTo()方法。

http://jsbin.com/iGOmEXeP/6/edit http://jsbin.com/iGOmEXeP/6/edit

Update your bin to include it like so: 更新您的垃圾箱,使其包含如下内容:

$("select").change(function() {
  var $this = $(this);

  if($this.val() === "1") {
   pos = new google.maps.LatLng(-24.397, 150.644);
  } else if($this.val() === "2") {
    pos = new google.maps.LatLng(-44.397, 150.644);
  } 
  map.panTo(pos);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM