私の Web アプリでは、ユーザーが入力した情報に戻って編集できるようにしています。ただし、何らかの理由で再送信すると、場所の緯度/経度が再計算されません。これは、勤務地を変更しない場合に発生します。ユーザーの介入なしに Google マップにその仕事の場所を見つけさせる方法はありますか?
私のコードは以下の通りです:
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);
私は本当に助けていただければ幸いです!ありがとう