gpt4 book ai didi

php - map 距离错误

转载 作者:行者123 更新时间:2023-11-30 22:19:43 26 4
gpt4 key购买 nike

好吧,我想我只是因为我的大脑衰竭而把一切都搞砸了。

我遵循了 Google 的“phpsqlsearch_v3”示例:

  • 导入sql文件
  • 将查询从显示英里更改为公里
  • 使用这个进行测试:

    phpsqlsearch_genxml.php?lat=37.315903&lng=-121.977928&radius=40

万物皆有魅力...

enter image description here

进入网站获取latlong,在数据库中添加和更改一些数据现在,我正在将 phpsqlsearch_genxml.php 更改为...

phpsqlsearch_genxml.php?lat=59.627847&lng=17.838589&radius=40

...没什么...但是,如果我将半径更改为 8000,它会起作用,但输入周围的距离将像 5665.231121242624km 但如果我翻转输入,因为我在地球的右侧眨眼 眨眼

phpsqlsearch_genxml.php?lat=17.838589&lng=59.627847&radius=100

它会给我一个更准确的结果,但是……结果应该更近,大约 1-2 公里……

建议现在做什么?

最佳答案

function getAddress($lat, $lng) {
$use_curl = false;
if ($use_curl) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lng . "&sensor=true");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array (
"Content-type: application/binary"
));
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
if (curl_errno($ch))
return -1;
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$str = substr($response, $header_size);
curl_close($ch);
$data = json_decode($str, true);
if (isset($data["results"]) && is_array($data["results"])) {
$street = $data["results"][0]["formatted_address"];
$ac = $data["results"][0]["address_components"];
$len = count($ac);
$i = 0;
$city = "";
while ($i<$len) {
if (in_array("locality", $ac[$i]["types"])) $city = $ac[$i]["long_name"];
else if (in_array("country", $ac[$i]["types"])) $city .= ",".$ac[$i]["short_name"];
$i++;
}
$meta = array(
"status"=>200,
"message"=>"Succeed."
);
return array("meta"=>$meta, "response"=>array("address"=>$street, "city"=>$city));
} else {
$meta = array(
"status"=>406,
"message"=>"Address is not known."
);
return array("meta", $meta);
}
} else {
$str = @file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lng . "&sensor=true");
$data = json_decode($str, true);
if (isset($data["results"]) && is_array($data["results"])) {
$street = $data["results"][0]["formatted_address"];
$ac = $data["results"][0]["address_components"];
$len = count($ac);
$i = 0;
$city = "";
while ($i<$len) {
if (in_array("locality", $ac[$i]["types"])) $city = $ac[$i]["long_name"];
else if (in_array("country", $ac[$i]["types"])) $city .= ",".$ac[$i]["short_name"];
$i++;
}
$meta = array(
"status"=>200,
"message"=>"Succeed."
);
return array("meta"=>$meta, "response"=>array("address"=>$street, "city"=>$city));
} else {
$meta = array(
"status"=>406,
"message"=>"Address is not known."
);
return array("meta"=>$meta);
}
}
}

关于php - map 距离错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36981341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com