Categories
HTML-JS-CSS

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.
mapsCentered

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);

Or,

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 : http://ipinfodb.com/ip_query.php

Coping with incompatible browsers

By Immanuel Noel

A techie at heart. Works with Adobe at Bangalore, India. Currently do DevOps. Been a part of the ColdFusion Engineering team and the Flash Runtime Engineering team in the past. Was also a Flash Platform Evangelist, evangelizing the Adobe Flex platform. Spoke at numerous ColdFusion / Flash and Flex tech conferences. This blog is a collection of the more interesting problem and solutions I have worked on.

More on me on the home page

7 replies on “Maps : Zoom into appropriate location”

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

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

Thanks for the info, now I will not tolerate such a mistake ….

Leave a Reply

Your email address will not be published. Required fields are marked *