10
我使用的是自動完成的方法來獲得地方建議,當我點擊我想要選擇的地方時,我想提取下面place.geometry.location
下的Lat
和Lng
。谷歌地圖得到LatLng值
按我的觀察,按鍵ib
和jb
保持與每個會話改變。有什麼辦法可以預測地提取Lat
和Lng
?
$(document).ready(function() {
var mapOptions = {
center : new google.maps.LatLng(-33.8688, 151.2195),
zoom : 13,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
$('#searchTextField').bind('keydown keypress', function() {
setTimeout(function() {
var inputQuery = $('#searchTextField').val();
if (inputQuery.length >= 2) {
//console.log(inputQuery);
/*
var service = new google.maps.places.AutocompleteService();
service.getPlacePredictions({
input : inputQuery
}, callback);
*/
var input = document.getElementById('searchTextField');
var options = {
types : ['geocode']
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
// Acting on Selecting a place
google.maps.event.addListener(autocomplete, 'place_changed', function() {
//infowindow.close();
var place = autocomplete.getPlace();
console.log(place);
console.log(place.formatted_address);
console.log(place.name);
console.log(place.geometry.location);
console.log(place.geometry.location[0]);
// Show the map to the current location selected
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17);
// Why 17? Because it looks good.
}
var marker = new google.maps.Marker({
position : place.geometry.location,
map : map,
draggable : true,
});
$.each(place.geometry.location, function(key, value) {
console.log(key + ": " + value);
});
});
}
}, 0);
});
});
非常感謝:D – 2013-03-09 20:39:04
我的榮幸,我很高興這很有幫助。 – 2013-03-09 21:01:23
也很高興爲我的問題找到解決方案.. – WorM 2013-09-13 11:23:08