//window.onload = function() { setTimeout(scrollTo, 100, 0, 1); } /* 初期設定 */ var directionsDisplay = new google.maps.DirectionsRenderer(); var directionsService = new google.maps.DirectionsService(); var shopPos = new google.maps.LatLng(35.439543, 139.62695); //お店の座標 var map; $(document).ready(function(){ map = new google.maps.Map(document.getElementById("map_canvas"), { zoom: 18, //デフォルトの拡縮の比率 scaleControl : false, streetview : true, mapTypeControl: false, //航空写真表示とかのマップタイプON・OFF切り替え mapTypeId: google.maps.MapTypeId.ROADMAP, //デフォルト時の地図の種類(これは普通の地図) center: shopPos //デフォルト時の中央の位置 }); var marker = new google.maps.Marker({ position: shopPos, icon : "http://www.yk-bully.com/map/images/ipn/arrow.png", //マーカー画像のURL map: map, title: '鶯谷スポーツパフェ' //マーカーのタイトル }); directionsDisplay.setMap(map); //zoomIn $(this).find('#zoomIn').click(function() { zoom = map.getZoom(); map.setZoom(zoom + 1); }); //,zoomOut $(this).find('#zoomOut').click(function() { zoom = map.getZoom(); map.setZoom(zoom - 1); }); //クリックで位置情報取得・ルート表示 $('#root').click(function(){myLocation();}); //mapSize $('.map').height(window.innerHeight-80); $(window).resize(function(){ $('.map').height(window.innerHeight-80); }); //myLocation(); }); /*GPSで現在位置を取得する*/ function myLocation(){ //Geolocation APIで位置を取得 AndroidはGoogle Gearsで位置情報取得 var geo = navigator.geolocation || google.gears.factory.create('beta.geolocation'); if(geo){ geo.getCurrentPosition( function(pos){ var my_lat = pos.coords.latitude; //緯度 var my_lng = pos.coords.longitude;//経度 //取得したデータからルート表示を実行 calcRoute(my_lat, my_lng);//ルート表示処理へ }, function(){ alert('位置情報を取得できませんでした'); },{ enableHighAccuracy:true //AndroidはこれがtrueじゃないとGPS情報を拾いにいかないようです… } ); } } /*受け取った座標からお店へのルートを表示*/ function calcRoute(my_lat, my_lng) { var request = { origin:shopPos, //お店の位置 destination:my_lat + ',' + my_lng, //取得した緯度・経度を整形して入れとります travelMode: google.maps.DirectionsTravelMode.WALKING //ルート算出タイプ。ここでは徒歩になってます。 }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); }