2012-06-28 23 views
0

我試圖在LatLng上居中放置地圖,但我不確定如何這樣做。我有這個IFRAME鏈接:如何居中Google地圖的腳本地圖

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" 
marginwidth="0" src="https://maps.google.es/maps?f=q&amp;source=embed&amp; 
hl=es&amp;geocode=&amp;q=Cam%C3%AD+Vell+d'Altea,+33,+L'Alf%C3%A0s+del+Pi&amp; 
aq=0&amp;oq=cam%C3%AD+vell+d'altea+33&amp; 
sll=40.396764,-3.713379&amp;sspn=13.49375,19.753418&amp;ie=UTF8&amp;hq=&amp; 
hnear=Cam%C3%AD+Vell+d'Altea,+33,+03581+L'Alf%C3%A0s+del+Pi,+Alicante,+Comunidad+ 
Valenciana&amp;t=m&amp;ll=38.570757,-0.076316&amp;spn=0.001743,0.004128&amp; 
z=14&amp;layer=c&amp;cbll=38.570736,-0.076335&amp;panoid=DplK9JGOu0KAPqoT95VMgQ&amp; 
cbp=12,309.4,,0,8.19&amp;output=svembed"></iframe><br /><small> 

我希望它是使用谷歌API的腳本位置。我有這樣的代碼:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <style type="text/css"> 
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0 } 
    #map_canvas { height: 100% } 
</style> 
<script type="text/javascript" 
    http://maps.googleapis.com/maps/api/js?key=MY_KEY&sensor=false&callback=initialize> 
</script> 
<script type="text/javascript"> 
    function initialize() { 
    var myOptions = { 
     center: new google.maps.LatLng(13.49375,19.75341), 
     zoom: 12, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 
    } 
    function loadScript() 
    { 
    var script = document.createElement("script"); 
    script.type = "text/javascript"; 
    script.src = "http://maps.googleapis.com/maps/api/js?key=MY_KEY&sensor=false&callback=initialize"; 
    document.body.appendChild(script); 
    } 
    window.onload = loadScript; 
</script> 

但我想把iframe的具體地址給谷歌API我只是複製。我不知道這麼做很熱。

那麼,我該如何鏈接Google maps API上的地圖呢?

非常感謝。

回答

0

這樣做的簡單方法是使用地圖編碼服務,例如maps.huge.info/pinpointaddress.htm,它提供了一些座標。 (對於那個,你需要稍微移動標記才能顯示座標)。

然後,用正確的座標,您的代碼替換13.49375,19.75341,說38.570918,-0.076218

center: new google.maps.LatLng(38.570918,-0.076218), 

 


不要問多個問題一次。請詢問關於StreetView的另一個問題。目前尚不清楚您是在您的API地圖或Google地圖地圖中詢問Streetview。

+0

你的意思是用這個腳本代替src嗎?