How to make a google map to point by default to the USA?
in the onloa开发者_JAVA百科d event I want to load a google map to show the USA.
What values do I need to put in the options {}? var myOptions = {
zoom: 4,
??????,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
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:
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);
}));
});
精彩评论