我是要從網頁中資料庫裡的地址去讀出google map位址
如果是在同一個網頁上執行,就沒問題
如果新開啟網頁來顯示地圖,會有開啟後,沒執行js的函數
(本身剛碰獨js,code是抓下來修改的,請前輩指導,感激不盡!)
--------------(這是準備開啟電子地圖的網頁) <input type="hidden" name="Addr" value="<?php echo $row_hous\
e_qry_2['Addr']; ?>"/>
(用hidden來讀取Addr的資料)
<input name="button" type="button" value="Search" onclick="j\
avascript:
window.open('myp.php?Addr=<? echo $row_house_qry_2['Addr'];?\
>'addressGps();)
" /> (重點在於我不知怎麼開啟新頁後,直接讀取 addressGps();) -------------(這是js)function load() {
if (GBrowserIsCompatible()) {
myMap = new GMap2(document.getElementById("my_map"));
var myLatLng = new GLatLng(25.04763902653048, 121.517157554626\
46);
myMap.setCenter(myLatLng, 15);
myMap.addControl(new GLargeMapControl());
document.getElementById('inLatLng').value = myLatLng.toString();
document.getElementById('inLat').value = myLatLng.lat();
document.getElementById('inLng').value = myLatLng.lng();
myMarker = new GMarker( myLatLng );
myMap.addOverlay( myMarker );
}
}
function addressGps() {
var myGeocoder = new GClientGeocoder();
var address = document.getElementById('address').value;
myGeocoder.getLatLng(address, function getRequest( point ){
if(!point){
alert('地址錯誤');
}else{
if(!point){
alert('地址錯誤');
}else{
myMap.panTo( point );
myMarker.setLatLng(point);
document.getElementById('inLatLng').value = point.toString();
document.getElementById('inLat').value = point.lat();
document.getElementById('inLng').value = point.lng();
}
});
}
//]]>
</script> [ 本帖最後由 s0926165 於 2009-10-29 23:39 編輯 ] |