Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a google map to point by default to the USA?

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 {}?

   var myOptions = {
      zoom: 4,
      ??????,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
like image 255
Itay Moav -Malimovka Avatar asked Jul 11 '11 22:07

Itay Moav -Malimovka


1 Answers

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);
      }));
    });
like image 160
David Rice Avatar answered Nov 14 '22 21:11

David Rice