我有一个网站,可以检查许多在线数据库上的用户 IP 地址,并获得纬度和经度的响应。
这是一个例子:
Array
(
[0] => stdClass Object
(
[statusCode] => OK
[statusMessage] =>
[ipAddress] => 37.6.226.186
[countryCode] => GR
[countryName] => GREECE
[regionName] => ATTIKI
[cityName] => ATHENS
[zipCode] => -
[latitude] => 37.9795
[longitude] => 23.7162
[timeZone] => +03:00
)
[1] => stdClass Object
(
[ip] => 37.6.226.186
[country_code] => GR
[country_name] => Greece
[region_code] =>
[region_name] =>
[city] =>
[zipcode] =>
[latitude] => 39
[longitude] => 22
[metro_code] =>
[areacode] =>
)
[2] => stdClass Object
(
[source] => smart-ip.net
[host] => 37.6.226.186
[lang] => en
[countryName] => Greece
[countryCode] => GR
[city] =>
[region] =>
[latitude] => 39.0000
[longitude] => 22.0000
[timezone] =>
)
)
我注意到有时 1 个响应可能会完全显示一个不相关的地方,因此纬度 + 经度不好。
您将如何解决这样的问题?也许循环遍历结果并检查最接近的值,然后选择 1 个响应?我不确定这一点,因为我是 php 的初级人员。任何指导或参考将不胜感激。