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
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
- 2 why dont you google it?? – Vicky Gonsalves Commented Jan 23, 2014 at 10:57
- 1 @Vicky Gonsalves: i did, but it not working properly... – VishnuPrasad Commented Jan 23, 2014 at 11:00
- Post your code that isnt working, and you can get help fixing it. This question is too vague and there are too many unknowns for it to be answered as-is. – Nick Sweeting Commented Jan 23, 2014 at 11:04
- 1 I tried with gmaps.js – VishnuPrasad Commented Jan 23, 2014 at 11:18
- Your question seems to duplicate stackoverflow.com/questions/4937517/… – Zinovy Nis Commented Jan 23, 2014 at 11:31
4 Answers
Reset to default 8just 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..
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.
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.
freegeoip.net provides a public HTTP API to search the geolocation of IP addresses. It uses a database of IP addresses that are associated to cities along with other relevant information like time zone, latitude and longitude.
You're allowed up to 15,000 queries per hour. If you need more than that, you can run the freegeoip as a web server on your own infrastructure. See: freegeoip on github