从IP地址获取地理位置 [英] Getting geolocation from IP address
问题描述
我需要跟踪用户详细信息,需要该客户的位置和IP地址。
我从
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();
现在问题是如何使用他们各自的IP地址在google地图中定位他们的位置
in codiigniter.
Now the problem is how can i make their location in google map by using their respective IP address
推荐答案
strong> ipinfo.io 在
just use ipinfo.io at
它使用一个位置api,我们可以发布ip地址,它将返回位置详细信息为json:
it uses a location api that we can post ip address and it will returns the location details as json:
我们可以使用从json回应google Maps API的经度和纬度细节在地图上显示位置。
we can able to display the loacation on map with the langitude and longitude details from json response to google Maps API.
这里是我使用的代码:
此脚本创建一个带有latticeitude&从json响应的经度:
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");
});
,地图将显示在:
<div style="border:1px solid red; height:745px;" id="map"></div>
Google Maps API gmaps.js 来运行此操作。
Google Maps API gmaps.js is needed to run this..
这篇关于从IP地址获取地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!