我正在阅读谷歌的API,但没有看到任何例子,而且所有其他的Google-by me示例都有点旧(大约1到2岁,大多数是基于API键的:S)。
我想要文字输入。发送按钮。如果在下面。
如何使用我自己的输入在地图上显示位置?
此时此刻,我的iframe看起来是这样的:
<iframe width="230" height="180" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<?php echo $src ?>">输入:
<input id="googleMaps" name="googleMaps" type="text" />此时,我正在尝试使用XML (但据我所知,JSON是推荐的?),但我在iframe中只获得了XML文本,比如:
This document had no style information.
<GeocodeResponse>
<status>
OK
</status>
<result>
<type>
locality
</type>
<type>
political
</type>
<formatted_address>
(...)如何将这些数据传递给Google并获取地图?:)
非常感谢。
发布于 2010-11-21 16:50:08
您需要使用Geocode来反转您的地址,以获得协调,然后可以用来在地图上显示结果。例如,对于我的地址,我发布地址参数,如下面的url所示。
http://maps.googleapis.com/maps/api/geocode/json?address=154+Metro+Central+Heights+London+UK&sensor=true协调可以从产生的JSON中获得,如下所示
"geometry": {
"location": {
"lat": 51.5001524,
"lng": -0.1262362
}PHP代码以获得JSON
<?php
$address = $_GET['address'];
$address=str_replace(" ","+",$address);
if ($address) {
$json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$address.
'&sensor=true');
echo $json;
}
?>Javascript可以找到这里。下面给出分析JSON的关键代码
$.getJSON("getjson.php?address="+address,
function(data){
lat=data.results[0].geometry.location.lat;
lng=data.results[0].geometry.location.lng;
//.... more map initialization code
}
);我已经为您之前的问题这里建立了一个工作示例,它将帮助您理解如何在地图上生成标记。如果你需要进一步澄清,请告诉我。
https://stackoverflow.com/questions/4238333
复制相似问题