GeoIP Plugin for Leaflet.js
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4296e12 Jun 30, 2018
Failed to load latest commit information.
LICENSE Updating readm to reflect changes in the centerMapOnPosition method Nov 2, 2014
leaflet-geoip.js https Jun 7, 2017


GeoIP Plugin for Leaflet.js. This plugin allows you to find the approximate position of the client machine based on their IP address. Additionally, you can center the map on this location.


Include the .js file in your html file.

  <script src="leaflet-geoip.js"></script>

Get the approximate position of the client machine as a L.LatLng object:

  var pos = L.GeoIP.getPosition();

Centre the map on the approximate location of the client machine (note: the centerMapOnPosition function calls getPosition):

  //initialise your map into
  //var map;


You have the possibility to pass a zoom parameter as well:

  L.GeoIP.centerMapOnPosition(map, 15);

You can also do the same for the location of an arbitraty IP address:

  var ip = "";
  var zoom = 15;
  var pos = L.GeoIP.getPosition(ip);
  //initialise your map into
  //var map;
  L.GeoIP.centerMapOnPosition(map, zoom, ip);