php - 使用 JavaScript 或 PHP 从地址返回经度和纬度的基本 API

标签 php javascript

我对 JavaScript 还很陌生,我正在寻找一个基本的 API 或函数,我可以将地址作为字符串值提供,并返回该地址的经度和纬度。我在数据库中有一系列地址,我想为每个地址添加经度和纬度值。

谢谢

最佳答案

使用 php 查找以下示例

<?php
$address ="1600+Amphitheatre+Parkway,+Mountain+View,+CA";
$url ="http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=false";
$getAddress = simplexml_load_file($url);
print"<pre>";
print_r($getAddress);
?>

它返回获取纬度/经度所需的所有详细信息,如下所示。

<?php
print"<pre>";
print_r((string)$getAddress->result->geometry->location->lat); echo "<br />";
print_r((string)$getAddress->result->geometry->location->lng);
?>

欲了解更多详情,请点击以下链接:

http://code.google.com/apis/maps/documentation/geocoding/

关于php - 使用 JavaScript 或 PHP 从地址返回经度和纬度的基本 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077176/

相关文章:

javascript - 使用 Nodejs 的多个用户输入

php - MySQL 用每个表的 where 子句连接三个表

javascript - 从 parent 到 child 应用相同的填充值?

php - (Ajax + PHP)我的 Google map 消失了

php - 算法问题 : select two stories per topic so that the same story is never selected for two different topics

javascript - opencart 2.1.0.1 bootstrap 3.3.5 全宽下拉菜单

javascript - 为什么字符串中的等号会抛出意外的标记错误?

javascript - 通知代码无效

javascript - 提交后如何禁用输入字段

java - 如何知道应用程序用户是否离线android应用程序?