Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting geolocation from IP address

I need to track user details, for that client's location and IP address is needed.
I got IP address from

$this->input->ip_address();

in codiigniter.
Now the problem is how can i make their location in google map by using their respective IP address

like image 744
VishnuPrasad Avatar asked Jan 23 '14 10:01

VishnuPrasad


People also ask

How to get geolocation information from IP address in API?

IP API is free and easy to use and integrate with your C# applications. You have to just send HTTP GET request along with the IP address to the below API URL to get geolocation information.

What is IP-based geolocation?

IP-based Geolocation is mapping of an IP address or MAC address to the real-world geographic location of an Internet-connected computing or a mobile device. Geolocation involves in mapping IP address to the country, region (city), latitude/longitude, ISP and domain name among other useful things.

How to get the real-world geographic location information from the IP address?

Sometimes you may need to get the real-world geographic location information from the visitor's IP address in your web application. IP Geolocation API ipgeolocationapi.com is a free real-time IP to Geolocation JSON API, which provides you the real-world geographic location of an Internet-connected computer terminal or device.

What is IPIP geolocation and how does it work?

IP Geolocation is a technique to lookup for visitor\'s geolocation information, such as country, region, city, ZIP code/postal code, latitude, longitude, domain, ISP, area code, mobile data, weather data, usage type, proxy data, elevation and so on, using an IP address.


3 Answers

just use ipinfo.io at

http://ipinfo.io/

it uses a location api that we can post ip address and it will returns the location details as json:

we can able to display the loacation on map with the langitude and longitude details from json response to google Maps API.

Here is the code i used:

this script creates a Google Map instance with lattitude & longitude from json response:

jQuery(document).ready(function(){
    jQuery.get("http://ipinfo.io/202.88.237.138", function (response)
               {
                   var lats = response.loc.split(',')[0]; 
                   var lngs = response.loc.split(',')[1];
                   map = new GMaps({
                       el: '#map',
                       lat: lats, //latitude
                       lng: lngs //longitude
                   });

               }, "jsonp");
});

and the map will displayed on:

<div style="border:1px solid red; height:745px;" id="map"></div>

Google Maps API gmaps.js is needed to run this..

like image 124
ReNiSh AR Avatar answered Oct 19 '22 10:10

ReNiSh AR


As a viable (although often less accurate) alternative, the HTML5 spec includes Geolocation. As HTML 5 becomes more and more prevalent I think we can expect to see this become standard in the future. It also does not require the use of external web services or libraries. Everything you need to geolocate is built right into the clients browser.

I believe the primary method used is IP address as specified.

like image 3
ChrisSwires Avatar answered Oct 19 '22 08:10

ChrisSwires


The Google Maps API will do the work of finding location using geoip for you. If the user is on a mobile device or has a more accurate way of locating themselves (like a GPS), it'll use that instead.

Here's a good starting point:
https://google-developers.appspot.com/maps/documentation/javascript/examples/map-geolocation

If you absolutely need to fetch location from IP only, there are third-party tools that you can scrape to get this information. You should make sure you have permission beforehand if you're using this in a larger project.

like image 2
Nick Sweeting Avatar answered Oct 19 '22 08:10

Nick Sweeting