教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php获取某个地址经纬度的代码

php获取某个地址经纬度的代码

发布时间:2015-12-20   编辑:jiaochengji.com
如何使用 Google Maps API 获得某一特定地点的经度和纬度呢?本文为大家提供一个函数,它以某一地址作为参数,返回一个数组,包含经度和纬度数据。有需要的朋友,可以参考下。

代码如下:

<?php
/**
 * 获取某地址的经纬度
 * by http://www.jbxue.com
*/
function getLatLong($address){ 
    if (!is_string($address))die("All Addresses must be passed as a string"); 
    $_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address)); 
    $_result = false; 
    if($_result = file_get_contents($_url)) { 
        if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false; 
        preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match); 
        $_coords['lat'] = $_match[1]; 
        $_coords['long'] = $_match[2]; 
    } 
    return $_coords; 
}
?>

您可能感兴趣的文章:
php获取某个地址经纬度的代码
php计算两个经纬度地点之间距离的方法分享
js获取ip地址利用谷歌地图获得经纬度
python爬取饿了么
python 怎么调用百度地图api
PHP计算地球上两点之间的距离(示例详解)
python可以用百度api接口吗?
PHP计算百度地图两个GPS坐标之间的距离代码
php计算距离的代码一例
Golang 的 “omitempty” 关键字略解

[关闭]
~ ~