P粉3863180862023-07-27 14:56:55
很抱歉,使用这个新版本后,坐标看起来是正确的。
function getCoordinates1($address, $city, $postalCode, $region, $province) { $url = 'https://maps.googleapis.com/maps/api/geocode/json?'; $addressString = "$address, $postalCode, $city, $province, $region"; $params = array( 'address' => urlencode($addressString), 'key' => 'my-code' ); $url .= http_build_query($params); $response = file_get_contents($url); $data = json_decode($response, true); if ($data['status'] === 'OK') { $latitude = $data['results'][0]['geometry']['location']['lat']; $longitude = $data['results'][0]['geometry']['location']['lng']; return array('latitude' => $latitude, 'longitude' => $longitude); } else { return false; } }