从标记返回地址
我对反向地理编码很陌生。我已经设法在地图上放置一个可拖动的标记,当放置该标记时,使用以下代码将纬度/经度返回到表单上的文本框:
div id="map" style="width: 600px; height: 467px"></div>
<script type="text/javascript" src="http://maps.google.com/maps?
file=api&v=2&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></script>
<script type="text/javascript">
<!--
if (GBrowserIsCompatible())
{
// create map and add controls
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.enableScrollWheelZoom();
//map.enableGoogleBar();
// set centre point of map
var centrePoint = new GLatLng('53.767789993998804', '-2.7046966552734375');
map.setCenter(centrePoint, 10);
// add a draggable marker
var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);
// add a drag listener to the map
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat().toFixed(5);
document.getElementById("longitude").value = point.lng().toFixed(5);
});
}
</script>
这很好用,但我也想将街道名称捕获到文本框中,但我迷路了。我知道我不能使用“点”来做到这一点,并且必须定义一个函数,但我完全迷失了,谷歌搜索对于像我这样开始的人来说没有任何用处。
任何指示将不胜感激。
谢谢
I'm very new to reverse geocoding. I have managed to place a dragable marker on a map which when dropped returns the Lat/Long to text boxes on a form using the code below:
div id="map" style="width: 600px; height: 467px"></div>
<script type="text/javascript" src="http://maps.google.com/maps?
file=api&v=2&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></script>
<script type="text/javascript">
<!--
if (GBrowserIsCompatible())
{
// create map and add controls
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.enableScrollWheelZoom();
//map.enableGoogleBar();
// set centre point of map
var centrePoint = new GLatLng('53.767789993998804', '-2.7046966552734375');
map.setCenter(centrePoint, 10);
// add a draggable marker
var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);
// add a drag listener to the map
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("latitude").value = point.lat().toFixed(5);
document.getElementById("longitude").value = point.lng().toFixed(5);
});
}
</script>
This works fine but I would also like to capture the street name to a text box but am lost. I know I can't do it using 'point' and have to define a function but am completely lost and google searches have turned up nothing of use to someone starting out like me.
Any pointers would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想答案就在这里:
http://code.google.com/apis/maps/documentation /javascript/services.html#ReverseGeocoding
但您需要升级到 Google Maps API 版本 3。
I reckon the answer is here:
http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding
But you'll need to upgrade to version 3 of Google Maps API.