0

在我的网络应用程序中,我让用户能够返回并编辑他们输入的信息。但是,由于某种原因,当他们重新提交时,位置纬度/经度不会重新计算。当他们不改变工作地点时,就会发生这种情况。有没有办法让谷歌地图在没有任何用户干扰的情况下找到工作地点?

我的代码如下:

var jobLocationChanged = false;
var jobLocationpickChanged  = false;
function initialize() {
  var defaultBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(37.348565,-122.263069),
      new google.maps.LatLng(37.496039,-122.062912));

  var options = {
    bounds: defaultBounds,
    componentRestrictions: {country: 'us'}
  };

  var input = document.getElementById('jobLocation');
  var autocomplete = new google.maps.places.Autocomplete(input, options);

  google.maps.event.addListener(autocomplete, 'place_changed', function() {
      var place = autocomplete.getPlace();
      if (!place.geometry) {
        // Inform the user that a place was not found and return.
        return;
      }
      $('#jobLocation-lat').val(place.geometry.location.lat());
      $('#jobLocation-lng').val(place.geometry.location.lng());
      //$('#jobLocation-pos-label').text('Lat  : '+place.geometry.location.lat()+', Lng  : '+place.geometry.location.lng());
      jobLocationChanged = false;
  });

    var input2 = document.getElementById('jobLocationpick');
    var autocomplete2 = new google.maps.places.Autocomplete(input2, options);

    google.maps.event.addListener(autocomplete2, 'place_changed', function() {
      var place = autocomplete2.getPlace();
      if (!place.geometry) {
        // Inform the user that a place was not found and return.
        return;
      }
      $('#jobLocationpick-lat').val(place.geometry.location.lat());
      $('#jobLocationpick-lng').val(place.geometry.location.lng());
      //$('#jobLocationpick-pos-label').text('Lat  : '+place.geometry.location.lat()+', Lng  : '+place.geometry.location.lng());
      jobLocationpickChanged = false;
    });



}
google.maps.event.addDomListener(window, 'load', initialize);

我真的很感激任何帮助!谢谢

4

1 回答 1

0

您可以通过自动完成服务请求给定字符串的预测

于 2013-11-05T01:37:18.540 回答