0

如何GLatLng()用表单控件值替换纬度和经度?

例子:

$(document).ready(function(){
    var map = new GMap2($("#map").get(0));
    var burnsvilleMN = new GLatLng(18.502401,-68.391953);
    map.setCenter(burnsvilleMN, 10);

像这样的东西,但它不工作:

$(document).ready(function(){
    var map = new GMap2($("#map").get(0));
    var burnsvilleMN = new GLatLng(DOCUMENT.FORM.CONTROL.VALUE);
    map.setCenter(burnsvilleMN, 10);
4

2 回答 2

2

You can use jQuery to retrieve just about any value in the document, but you have to know how to select it. If your form field has an ID attribute, say id="gmap-lat", just select that ID and use val() like this: $('#gmap-lat').val();

Note that you'll need use two values, and convert them into numbers using parseFloat().

于 2012-04-23T20:52:08.273 回答
1

从 Blaze 借一点(我忘了你需要为你的函数 GLatLng 解析字符串)

$(document).ready(function(){
  var map = new GMap2($("#map").get(0));
  var longitude = parseFloat($("#longitudeHiddenControl").val());
  var latitude = parseFloat($("#latitudeHiddenControl").val());
  var burnsvilleMN = new GLatLng(longitude, latitude);
  map.setCenter(burnsvilleMN, 10);
});
于 2012-04-23T20:56:01.580 回答