はじめまして、google ストリートビュー と map のAPIを学習していますyuuと申します。
マップと連動してストリートビューが動いてくれるようにしたいと思い、initializedイベントをGEvent.addListnerで
受け取って処理させるコードを記述したのですが、どうしてもうまくいきません。
様々なサイトをいろいろと見たのですが、どうしても自分の間違えの原因がわかりません。
どうか分かる方がいらしたら教えてください。
お願いいたします。
下にそのコードを記載します。(javascriptをHTMLから分離していないのはその方が対応がわかりやすいと思いそうしています)
下はコピペで動くはずです。キーの記載に問題がありましたら、すぐに編集致します。
<html>
<head>
<script src="
http://maps.google.co.jp/maps?
file=api&v=2.140&key=ABQIAAAAigLOLoZuOgwIE_rhlfDfsRTU0pOoM2KY0Y17OLvN-
J7zT0ldqBQTkyIQ7Y1s2QgOchiCKdjBA7HVtQ" type="text/javascript"
charset="utf-8"></script>
<title>Google Map API</title>
</head>
<script type="text/javascript">
//<![CDATA[
var map;//Map
var streetmap;//ストリートビュー
var client;//GStreetViewClient
var s_dlocation;//ストリートビューデフォルト位置
var m_dlocation;//GMapデフォルト位置
//main
window.onload = function(){
//defualt location デフォルト位置
initMap(35.658236, 139.745944);//Map初期化
}
//初期化 Map --> StreetView
//map初期処理
function initMap(lat,lng){
m_dlocation = new GLatLng(lat,lng);
map = new GMap2(document.getElementById("mymap"));
map.setCenter(m_dlocation,18);
map.addControl(new GMapTypeControl());//Control追加
map.addControl(new GSmallMapControl());//追加2
initPanorama(lat,lng);//Panorama初期化
}
//ストリートビュー初期化処理
function initPanorama(lat,lng){
s_dlocation = new GLatLng(lat,lng);
streetmap = new GStreetviewPanorama(document.getElementById
("viewArea"));
client = new GStreetviewClient();
client.getNearestPanoramaLatLng(s_dlocation,function(latlng){
if(latlng==null){
document.getElementById("viewArea").style.display="none";
return ;
}
s_dlocation = latlng;
streetmap.setLocationAndPOV(s_dlocation,{yaw: 180, pitch: 0, zoom:
-1});
GEvent.addListener(streetmap,"initialized",function(location){
test(location);
});
});
}
//初期化(修正処理)
function pano_ini(location){
var setlocation = new GLatLng(location.lat(),location.lng());
map.panTo(setlocation);
}
//initialized Event処理
function test(location){
var setlocation = new GLatLng(location.lat(),location.lng());
map.panTo(setlocation);
}
window.unload = GUnload;
//]]>
</script>
<body>
<div id="viewArea" style="width:450px; height=450px ";></div>
<div id="mymap" style="width:450px; height=450px ";></div>
<ol id="history"></ol>
</body>
</html>