您如何单击地图并填充表单中的纬度和经度字段? [英] How do you click on a map and have latitude and longitude fields in a form populated?

查看:32
本文介绍了您如何单击地图并填充表单中的纬度和经度字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,用户需要在需要标识位置的位置填写该表单.我在表单上有纬度和经度输入字段.我也在寻找十进制纬度和经度.我想要的似乎很简单.我只想有一个链接,用户可以点击它会弹出一个地图(谷歌或雅虎),他可以使用地图来查找位置,只需点击它,这将自动填充两个输入字段的纬度和离地图很远.以前有人这样做过吗?

I have a form that a user needs to fill out where the location needs to be identified. I have latitude and longitude input fields on the form. I am also looking for the decimal lat and long. What I would like seems really simple. I just want to have a link that the user can click on that would popup a map (google or yahoo) and he could use the map to find the location and just click on it and that would automatically populate the two input fields for lat and long from the map. Has anyone done this before?

推荐答案

使用 Google Maps API,您可以非常轻松地做到这一点.只需向您的地图对象添加一个点击事件处理程序,该处理程序将传递用户点击位置的纬度/经度坐标(请参阅 click 事件的详细信息此处).

Using the Google Maps API, you can do this pretty easily. Just add a click event handler to your map object, which passes in the latitude/longitude coordinates of where the user clicked (see details on the click event here).

function initMap()
{
    // do map object creation and initialization here
    // ...

    // add a click event handler to the map object
    GEvent.addListener(map, "click", function(overlay, latLng)
    {
        // display the lat/lng in your form's lat/lng fields
        document.getElementById("latFld").value = latLng.lat();
        document.getElementById("lngFld").value = latLng.lng();
    });
}

这篇关于您如何单击地图并填充表单中的纬度和经度字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆