How to make google map default for USA?

in the onload event, I want to load a Google map to show the USA.
What values ​​do I need to set in the {} parameters?

var myOptions = { zoom: 4, ??????, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
+6
source share
1 answer

Position it in the latitude and longitude of the USA and adjust the scale.

 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 searching 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); })); }); 
+15
source

Source: https://habr.com/ru/post/892537/


All Articles