问题:Google Maps Lat Long Picker - 1 个字段中的 lat long

我对用于自定义 Wordpress 短代码的 jQuery 插件有疑问。该插件是一个以 LatLong 作为输出的谷歌地图搜索表单。

插件链接:http://www.wimagguc.com/projects/jquery-latitude-longitude-picker-gmaps/我使用的示例代码来自:“可编辑和可选择的纬度/经度值”。

纬度和经度都作为隐藏输入输出。我希望在 1 个隐藏输入中输出纬度和经度。

示例输出:

<input type="text" class="gllpLatitude" value="52.372086">
<input type="text" class="gllpLongitude" value="4.898437">

期望的输出:

<input type="text" class="LatLong" value="52.372086,4.898437">

问题是:如何?!

这是插件的代码:http://www.wimagguc.com/projects/jquery-latitude-longitude-picker-gmaps/js/jquery-gmaps-latlon-picker.js

解答

您可以为此添加另一个隐藏字段。由于每当移动标记时都会触发location_changed事件,因此您可以轻松更新此值。您还需要在初始化时设置此值,因此如果用户提交 from 而不更改标记位置,latLng 值仍将正确设置。

$(document).bind("location_changed", function(event, object) {
    updateLatLng($(this));
});

$(".gllpLatlonPicker").each(function() {
    (new GMapsLatLonPicker()).init( $(this) );
    updateLatLng($(this));
});

function updateLatLng(object) {
    var lat = $(object).find('.gllpLatitude').val();
    var lng = $(object).find('.gllpLongitude').val();
    var latLng = lat + ',' + lng;
    $(object).find('.gllpLatLong').val(latLng);
}

在这里工作的小提琴

Logo

更多推荐