Check out http://www.ipinfodb.com/ . You can get the latitude and longitude by passing the IP address to your services. I recently did something when I created a simple service that grabbed the current IP address and then passed it to the service ("api / location / city" is just a service that curls the ipinfodb service). Using jquery:
$.get("api/location/city", null, function(data, textStatus)
{
if (data != null)
{
if (data.Status == "OK")
{
var lat = parseFloat(data.Latitude);
var lng = parseFloat(data.Longitude);
$.setCenter(lat, lng, $.settings.defaultCityZoom);
manager = new MarkerManager(map, {trackMarkers : true });
var e = $.createUserMarker(map.getCenter());
e.bindInfoWindowHtml($("#marker-content-event").html());
var m = [];
m.push(e);
manager.addMarkers(m, 10);
manager.refresh();
}
else
{
$.setCenter($.settings.defaultLat, $.settings.defaultLng, $.settings.defaultZoom);
}
}
}, "json");
The key here is the following line:
$.setCenter(lat, lng, $.settings.defaultCityZoom);
Just set the center to lat / lng of the service call result.
source
share