[問題] goole map api 動態抓取地址
我是要從網頁中資料庫裡的地址去讀出google map位址
如果是在同一個網頁上執行,就沒問題
如果新開啟網頁來顯示地圖,會有開啟後,沒執行js的函數
--------------(這是準備開啟電子地圖的網頁)
<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>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.66.61
→
10/29 17:13, , 1F
10/29 17:13, 1F
→
10/31 01:16, , 2F
10/31 01:16, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章