【问题标题】:google map problem [closed]谷歌地图问题[关闭]
【发布时间】:2009-11-02 21:00:43
【问题描述】:

我有一个谷歌地图并加载它,但我想通过改变中心来改变方向或中心,我该怎么做?我有这样的代码来加载地图:


function putmap(x) { if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("Map"));

            // Create new geocoding object
            geocoder = new GClientGeocoder();

            // Retrieve location information, pass it to addToMap()
            geocoder.getLocations(x, addToMap);

        }

}

我想通过在文本框中输入一个新值来更改 x 的值,我该怎么做...

【问题讨论】:

  • 我不确定您要做什么。您是 Google Maps API 还是只是想在地图上导航?
  • 我成功将地图加载到我的网页,但我想动态更改中心,我该怎么做?
  • 您的问题需要更多细节。请更新。
  • 是的,您只是在寻找setCenter 的文档吗?如果是这样,你去:code.google.com/apis/maps/documentation/v3/reference.html#Map

标签: google-maps many-to-many mashup


【解决方案1】:

好吧,你可以通过这样做来改变中心

map.setCenter(new GLatLng(lat, lng), map.getZoom());

查看here 了解更多详情。如果您知道所需的缩放级别,则可以使用它来代替 map.getZoom()

【讨论】:

  • 如果你不想改变缩放,你不需要指定它。只需使用:map.setCenter(new GLatLng(lat, lng));
【解决方案2】:

您使用的是 Map2 API 吗?如果是这样,只需使用setCenter() 方法:

var map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new google.maps.LatLng(0, 0), 2);

See the docs 获取更多入门帮助。

【讨论】:

    【解决方案3】:

    给你的文本框一个id,然后你就可以写了

    geocoder.getLocations(document.getElementById("mytextbox").value, addToMap);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-13
      • 2011-03-17
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 2020-05-23
      • 2011-10-26
      相关资源
      最近更新 更多