How can I center google map based on countrycode? -


According to the documentation, I have found this: geocoder.setBaseCountryCode (countrycode);

However

Any help?

Itemprop = "text">

GOCODerratBaseConverter code () will not center the map. This will set the base country for geocoding so that if you try to geocode 'Plymouth', then it will differentiate between the UK and Massachusetts cities.

If you want to specify the country code manually, you can use GClientGeocoder as the following:

  var Country_code = "ES"; // Change the country code here to function initialize () {if (GBrowserIsCompatible ()) {var map = null; Var Geocoder = Null; Map = new GMap2 (document.getElementById ("map_canvas")); GeoCoder = New GCLient Geocoder (); If (geododer) {geocoder.getLatLng ("country:" + countrycode, task (point) {if (point) {map.setCenter (point, 13);}}); }}}  

In this situation there is no need to set setBaseCountryCode () , because country codes are clearly unique.


If you are using version 3 of the Google Maps API, you can do this automatically in the country of client google.loader.ClientLocation you want to use. It uses the client's IP address to determine the country.

Code will look something like this:

  function initialize () {// start basic values ​​zoom = 3; Var latlng = new google.maps.LatLng (37.4419, -100.149); // If the customer loaded the loader loader, use that information if (google.loader.ClientLocation) {zoom = 13; Latlng = new google.maps.LatLng (google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude); } Var myOptions = {zoom: zoom, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP} var map = new google.maps.Map (document.getElementById ("map"), myOptions); }  

Note that Geolocation is not a very reliable science from IP address. You will get the location of your ISP, which can be very far, as well as the IP-to-location database is not always updated with the latest changes, so you do not have any data for a particular IP address. However, when you only examine the country, the difference in error will be quite small.



Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -