javascript 如何使谷歌地图默认指向美国?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6657213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a google map to point by default to the USA?
提问by Itay Moav -Malimovka
in the onload event I want to load a google map to show the USA.
What values do I need to put in the options {}?
在 onload 事件中,我想加载谷歌地图以显示美国。
我需要在选项 {} 中放入哪些值?
var myOptions = {
zoom: 4,
??????,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
回答by David Rice
Position it to the latitude and longitude of the USA, and adjust the zoom.
将其定位到美国的经纬度,并调整缩放。
var latlng = new google.maps.LatLng(37.09024, -95.712891);
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
In most browsers after you search for a place on google maps, you can put
在谷歌地图上搜索某个地点后,在大多数浏览器中,您可以输入
javascript:void(prompt('',gApplication.getMap().getCenter()));
in the address bar to get the latitude and longitude coordinates
在地址栏中获取经纬度坐标
Or you can use reverse geocoding with a name like "USA" which would be something like this:
或者,您可以使用名称为“USA”的反向地理编码,如下所示:
geocoder.geocode( {'address': 'USA' }, function(results, status) {
response($.map(results, function(item) {
var latlng = new google.maps.LatLng( item.geometry.location.lat(), item.geometry.location.lng());
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}));
});