Maps : Zoom into appropriate location

Visitors end up seeing the entire world on the map when GeoCoordinates are not available.

There are two ways to combat this,

Either position map (calculate longitude) based on the timezone from system date,
The entire map is still seen, but the map is positioned with the visitors location at the center.

Below is the map show to a visitor from northern South America, instead of all continents.

Here is how to do it,

//Language : Javascript

latitude = 51.50019435946635; // Latitude coordinate for GMT
var d = new Date();
longitude = 7 * -((d.getTimezoneOffset() / 60) * 2);


Use the free webservice provided by IP INFO DB.
This returns a XML file with sufficient data such as Location Name, Latitude, Longitude, etc.. However, With the best case scenario, this might only fetch you the city level geographical location, since this might just be the ISP’s location, which is of no use.

Try Out :

Coping with incompatible browsers

7 Responses to “Maps : Zoom into appropriate location”

  1. It is useful to try everything in practice anyway and I like that here it’s always possible to find something new. 🙂

  2. You have really great taste on catch article titles, even when you are not interested in this topic you push to read it

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>