首先這裏是我的代碼有問題:GMAP v3和JS不打漂亮
var geocoder;
var map;
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 18,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById("details"), myOptions);
var q = $("span#address").text() + ' ' + $("span#city").text() + ' ' +$("span#state").text() + ' ' +$("span#zip").text();
var t = document.getElementById('address').value;
console.log(t);
//var city = document.getElementById("home-city").value;
//console.log(city);
geocoder.geocode({ 'address': t}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
//draggable: true,
position: results[0].geometry.location
});
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
好了,我的問題是,我可以加載到geocoder.geocode()可變這樣
var address = "string address";
我想從特定頁面抓取地址並將地址存儲在一個var中,然後將該var傳遞給Gmaps,並且在完美的世界中這應該起作用!但它似乎沒有這樣的世界;-(
所以我做了一些測試,足夠有趣...
var q = $("span#address").text() + ' ' + $("span#city").text() + ' ' +$("span#state").text() + ' ' +$("span#zip").text();
的作品時,我做了的console.log(地址),我得到的地址outputed 。但是我不能將變量地址插入到地理編碼中,因爲它不會識別它。其次,我嘗試了很好的常規JavaScript方法,並嘗試使用地址唯一標識符來獲取元素的val。Firebug和地理編碼錯誤tell我認爲值是NULL ...
所以我很困惑,jQuery可以抓取數據,但不能傳入地理編碼。然後正常的JavaScript告訴我我瘋了,有沒有在數據領域我試圖通過ID參考...
任何人都得到了這樣的情況下工作?
嗯,也許我應該提一下,我有所有這些代碼在jQuery實時點擊功能上執行。當用戶點擊地圖圖標時,所有此代碼將假定執行...
是的,我使用.value,並給它一個隨機數字ID只是爲了確保我沒有錯,並且已經有一個具有相同ID的元素。但我仍然無效。並做了逗號事情 – Eli 2010-10-21 07:07:31