Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center Google Map on a country by name

I'm using the Google Maps API (v2) and would like to center the map onload to a country (for example england).

At the moment i center the map using:

map.setCenter(new GLatLng( 43.907787,-79.359741), 9);

But this obviously requires longitude and Latitude.

Any way to do this by inserting a name of a country?

like image 276
Shadi Almosri Avatar asked Nov 16 '09 19:11

Shadi Almosri


People also ask

How do you center in Google Maps?

Please go to your map and drag and drop your map to the position you wish. You can also zoom in your map a little bit with mouse wheel or zoom cotrols on the bottom right corner of the map. Please remember to save your map after any changes. Hope that helps.

Is there a way to display a single country in Google Map?

You can customize your map for a specific country or region in the following ways: Change the default language settings. Specify a region code, which alters the map's behavior based on a given country or territory.

How do you drag countries on Google Maps?

You can move the landmass by clicking on it, holding down the mouse button, and dragging.


1 Answers

var country = "United States"
var map = new GMap2($("#map")[0]);
map.setUIToDefault();

var geocoder = new GClientGeocoder();
geocoder.getLatLng(country, function (point) {
  if (!point) {
    // Handle error
  } else {
    map.setCenter(point, 8, G_PHYSICAL_MAP);
  }
});
like image 128
Bob Aman Avatar answered Sep 23 '22 06:09

Bob Aman