如何通过代码获取经度和纬度

3

我被要求找到特定地点的经纬度。用户将提供该位置的地址。我该如何获得经纬度?非常感谢您的任何建议。


你可以参考这个链接:{https://dev59.com/hG025IYBdhLWcg3weF6S} - Jen
2个回答

1

为了将地址文本转换成经纬度坐标对,您需要进行所谓的地理编码。通常,这方面的良好服务都有一定的配额或付费订阅模式,但您可以在以下网址找到一些免费的API:

http://www.programmableweb.com/news/7-free-geocoding-apis-google-bing-yahoo-and-mapquest/2012/06/21

进一步在Google上搜索,你会找到其他提供商,因为我已经提供了关键词:地理编码。许多人都有JavaScript、PHP、C#和其他实现示例,可以帮助你入门。


我会查看它的。谢谢你抽出时间。 :) - Jade Sayo

1
我在项目中使用Google API获取地址的地理坐标:
class Google
{
    private function __construct() { }

    public static function getGoogleJson($address)
    {
        $apiLink = 'http://maps.google.com/maps/api/geocode/json?sensor=false&language=ru&address=' . urlencode($address);

        $tmp = @json_decode(file_get_contents($apiLink));

        if (!$tmp) {
            return new stdClass;
        } else {
            return $tmp;
        }
    }

    public static function getGeoByAddress($address)
    {
        $addr = self::getGoogleJson($address);

        if (isset($addr->results[0]->geometry->location)) {
            return (array)$addr->results[0]->geometry->location;
        } else {
            return ['lat' => 0, 'lng' => 0];
        }
    }
}

注意!Google每天使用此API有一定限制。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接