【发布时间】:2019-10-23 18:53:39
【问题描述】:
我正在使用地理定位来检测未显示确切城市的当前城市,例如我在班加罗尔,它显示的是钦奈或有时是特里凡得琅。请让我知道如何准确显示当前城市。 下面是我的代码-
function fetch($host) {
if ( function_exists('curl_init') ) {
//use cURL to fetch data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'geoPlugin PHP Class v1.1');
$response = curl_exec($ch);
curl_close ($ch);
} else if ( ini_get('allow_url_fopen') ) {
//fall back to fopen()
$response = file_get_contents($host, 'r');
} else {
trigger_error ('geoPlugin class Error: Cannot retrieve data. Either compile PHP with cURL support or enable allow_url_fopen in php.ini ', E_USER_ERROR);
return;
}
return $response;
}
function convert($amount, $float=2, $symbol=true) {
//easily convert amounts to geolocated currency.
if ( !is_numeric($this->currencyConverter) || $this->currencyConverter == 0 ) {
trigger_error('geoPlugin class Notice: currencyConverter has no value.', E_USER_NOTICE);
return $amount;
}
if ( !is_numeric($amount) ) {
trigger_error ('geoPlugin class Warning: The amount passed to geoPlugin::convert is not numeric.', E_USER_WARNING);
return $amount;
}
if ( $symbol === true ) {
return $this->currencySymbol . round( ($amount * $this->currencyConverter), $float );
} else {
return round( ($amount * $this->currencyConverter), $float );
}
}
【问题讨论】:
-
你能显示你当前的代码吗?如果您向我们展示您在做什么,就更容易找到这本书。
-
请使用edit 按钮将其添加到问题中。使用正确的格式会更易读
-
请将代码附加到问题中,而不是作为 cmets。可以应用代码格式以提高可读性。
-
当然,添加了代码。请建议修复。提前致谢
标签: php geolocation ip-geolocation