我需要訪問JavaScript變量:JavaScript的變量
var geocoder = new google.maps.Geocoder();
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function(responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
function updateMarkerStatus(str) {
document.getElementById('markerStatus').innerHTML = str;
}
function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
function initialize() {
geocoder.geocode({ 'address': 'london'}, function(results, status) {
rr = results[0].geometry.location;
});
var latLng = new google.maps.LatLng(rr);
var map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 8,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
// Update current position info.
updateMarkerPosition(latLng);
geocodePosition(latLng);
// Add dragging event listeners.
google.maps.event.addListener(marker, 'dragstart', function() {
updateMarkerAddress('Dragging...');
});
google.maps.event.addListener(marker, 'drag', function() {
updateMarkerStatus('Dragging...');
updateMarkerPosition(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function() {
updateMarkerStatus('Drag ended');
geocodePosition(marker.getPosition());
});
// Onload handler to fire off the app.
google.maps.event.addDomListener(window, 'load', initialize);
這是整個腳本,我需要得到附近的地址先這樣通過某種方式處理,以轉換爲ltlng
@ user438755 - 請將您的代碼的每一行縮進4個空格,或者它未被格式化爲代碼。 – 2010-09-14 17:19:56
@Peter - 那麼我整天寫的,使用2個空格,沒有格式化爲代碼? – Jakob 2010-09-14 17:23:55
@Jakob [Nope](http://meta.stackexchange.com/questions/3122/formatting-sandbox/64504#64504)。 -----但它看起來像你經常[使用4個空格](http://stackoverflow.com/questions/3467820/xy-z5-how-are-parts-of-this-expression-called/3467922# 3467922)。 – 2010-09-14 18:31:14