从 wordpress 的文本框中获取纬度和经度值

Get Latitude and Longitude values from textbox in wordpress

我正在尝试显示 google 地图并希望从两个文本框中获取纬度和经度值。但它没有显示带有标记的 google 地图,我希望在我输入经度值后,google 地图应该显示我在经度和纬度文本框中输入的值。我在 wordpress

工作

下面是我的jquery

jQuery(document).ready(function () {

jQuery("#long").change(function () { 
//jQuery("div .googlemap").hide();

lat=jQuery("input #lat").val();
long=jQuery("input #long").val();

var myCenter=new google.maps.LatLng(lat,long);
initialize(lat,long);
function initialize()
{
    alert("yes initialize function finally fires");
var mapProp = {
  center: myCenter,
  zoom:5,
  mapTypeId: google.maps.MapTypeId.ROADMAP
  };

var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker = new google.maps.Marker({
  position: myCenter,
  title:'Click to zoom'
  });

marker.setMap(map);

// Zoom to 9 when clicking on marker
google.maps.event.addListener(marker,'click',function() {
  map.setZoom(9);
  map.setCenter(marker.getPosition());
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

});

HTML

<div class="row">
<div class="col-md-6">Latitude <input id="lat" style="height: 30px;" name="latitude" type="text" /></div>
<div class="col-md-6">Longitude <input id="long" style="height: 30px;" name="longitude" type="text" /></div>
</div>
<div id="googleMap" style="width:500px;height:380px;"></div>

谢谢

选择器中没有空格。

lat=jQuery("input#lat").val();
long=jQuery("input#long").val();

("input #something") 表示它选择所有输入的所有 children,id 为 #something。如果它没有找到任何东西,则 .val() returns undefined 和 map 不起作用。