На карте Google, когда я перетаскиваю маркер lat()
и lng()
значения, указанные в текстовых полях. Я хочу сделать, как здесь:geocode не определяет местоположение точки точно на карте google
Coordinates change for every movement
Мои следующие части кода работают на меня. Но, когда я тащу маркер далеко, он работает, но в небольшие расстоянияlat()
и lng()
не меняются?
Как решить эту проблему?
основные JS коды:
// fill in the UI elements with new position data
function update_ui(address, lat, lng) {
$('#lat').val(lat);
$('#lng').val(lng);
}
// move the marker to a new position, and center the map on it
function update_map(geometry) {
map.fitBounds(geometry.viewport)
marker.setPosition(geometry.location)
}
И геокод:
geocoder.geocode(request, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// Google geocoding has succeeded!
if (results[0]) {
// Always update the UI elements with new location data
update_ui(results[0].formatted_address, results[0].geometry.location.lat(), results[0].geometry.location.lng())
// Only update the map (position marker and center map) if requested
if (update) { update_map(results[0].geometry) }
} else {
// Geocoder status ok but no results!?
alert("Error occured. Please try again.");
}
} else {
// Google Geocoding has failed. Two common reasons:
// * Address not recognised (e.g. search for 'zxxzcxczxcx')
// * Location doesn't map to address (e.g. click in middle of Atlantic)
if (type == 'address') {
alert("Sorry! We couldn't find " + value + ". Try a different search term, or click the map.");
} else {
alert("Sorry! We couldn't find " + value + ". Try a different search term, or click the map.");
update_ui('', value.lat(), val.lng())
}
};
});
Edit:
Когда я перетащить маркер очень мало, координаты не меняются, но после того, как некоторые они меняются. Вот jsfiddle:
http://jsfiddle.net/jhoonbey/wwdE9/
У вас есть ссылка или jsfiddle, которая обнаруживает проблему? Не может ничего делать с фотографиями. Какова ценность обновления? Что делает update_map? – geocodezip
Нет, извините, я не могу добавить свой код в jsfiddle. Я отредактировал мой вопрос, добавил эту функцию. Теперь я узнаю. google.maps.GeocoderLocationType.ROOFTOP. Это тип, который геокодер находит точки точно. но я не могу установить этот тип в геокодер. –
@geocodezip, я поместил свой код в jsfiddle и отредактировал мой вопрос. Можете ли вы мне помочь? –