以名称google maps api v3为中心 [英] center on a country by name google maps api v3
本文介绍了以名称google maps api v3为中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能告诉我如何在谷歌地图api v3上按名称居中?我知道如何在v2中做到这一点,但需要在v3中做到这一点。
could someone tell me how to center on a country by name on the google maps api v3? I know how to do it in v2, but need to do it in v3.
干杯!
推荐答案
您可以使用地理编码查找国家的纬度/经度。
查看 sample from Google。
You could use Geocoding to lookup the Lat/Lng of the country.
Take a look at this sample from Google.
基本上你需要做像这样:
Basically you need to do something like this:
var country = "Germany";
var geocoder;
geocoder.geocode( {'address' : country}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}
});
在初始化函数中,您需要设置geocoder对象的值,如下所示:
In your initialize function you'll need to set the value of the geocoder object, like this:
geocoder = new google.maps.Geocoder();
您需要制定适当的缩放级别,然后设置以地图为中心。
You'd need to workout what an appropriate zoom level would be, and then set that after you have centered the map.
这篇关于以名称google maps api v3为中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文