Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel GoogleMapsAPI和GoogleSearch提供了不同的地理位置_Laravel_Google Maps_Curl_Google Maps Api 3_Geocode - Fatal编程技术网

Laravel GoogleMapsAPI和GoogleSearch提供了不同的地理位置

Laravel GoogleMapsAPI和GoogleSearch提供了不同的地理位置,laravel,google-maps,curl,google-maps-api-3,geocode,Laravel,Google Maps,Curl,Google Maps Api 3,Geocode,我试图得到一个地方的纬度和经度,然而,它返回的值与谷歌搜索提供的值不同 $url = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($request->address).",US&key=API_KEY"; try { $client = new \GuzzleHttp\Client(); $apiReque

我试图得到一个地方的纬度和经度,然而,它返回的值与谷歌搜索提供的值不同

        $url = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($request->address).",US&key=API_KEY";
        try {
            $client = new \GuzzleHttp\Client();
            $apiRequest = $client->request('GET', $url);
            $resp = json_decode($apiRequest->getBody());
        } catch (\Exception $re) {
            return response()->json([
                'sts' => -1,
                'message' => $re->getMessage()],
                500);
        }

        $latitude = $resp->results[0]->geometry->location->lat;
        $longitude = $resp->results[0]->geometry->location->lng;
因此,出于测试目的,我通过了
newyork
作为地址。它回来了

[location] => stdClass Object
                    (
                        [lat] => 43.2994285
                        [lng] => -74.2179326
                    )
然而,当我用关键字
latlong of New York
搜索时,它返回值

40.7128° N, 74.0060° W
我不明白为什么它返回的是
3度的差异
,我知道可能会有一些这样的细微差异,但是,3度的差异,是非常不方便的。
有什么东西我可能遗漏了吗?

我可以看到您已经对地址进行了地理编码“美国纽约”,地理编码员将其视为一个行政区域或一个州。请参见geocoder工具中的结果,该工具显示纽约州的大致位置
43.299429,-74.217933

另一方面,如果您对地址进行地理编码“”,则应获得纽约市的大致位置
40.712775,-74.005973


希望这能澄清这一点。

一个使用英里,一个使用公里。你也设定了缩放吗?这可能会有一些差异,在计算距离时也可以使用英里和公里,但是,到目前为止,我只是想得到纬度和经度。这不是你问的,你问为什么两者之间有差异我没有使用缩放。而且,我从来没有听说过缩放可以改变最终的纬度和经度值。到目前为止(获得纬度和经度),我认为这与公里和英里没有任何关系,因为“纽约”不仅仅是一个城市,也是一个州。因此,根据您使用的搜索类型或属性,它将返回这样或那样的结果。或者两者兼而有之。它返回一个或多个结果?。