ã¯ããã«
ãä»åã¯YOLPã®æä¾ããJavaScriptãããAPIãå©ç¨ãã¦ãç¾å¨å°ããæå®ããå ´æã¸ã®ã«ã¼ãæ¤ç´¢ãè¡ãã¤ã¤ãã«ã¼ãä¸ã®é¨é²ç¶æ³ããã¸ã¥ã¢ã«ã«ãã§ãã¯ã§ããã¹ããã»ã¿ãã¬ããç¨ã®Webã¢ããªãã«ã¼ãé¨é²ãã§ãã«ã¼ããä½ã£ã¦ã¿ããã¨æãã¾ããæ¬æã«æ²¿ã£ã¦å®éã«éçºãé²ããã¨ãç°¡åã«Webã¢ããªãä½æã§ãããã¨ãå®æãã¦ããã ããã¨æãã¾ãã®ã§ããã²ã試ããã ãããã¾ããã«ã¼ãé¨é²ãã§ãã«ã¼ããä»ãã試ãããæ¹ã¯ããã¡ããããå©ç¨ããã ãã¾ãã®ã§ããããã¦ã試ããã ããã
æ©è½æ¦è¦
ãä»åã®Webã¢ããªã§ã¯ã以ä¸ã®æ©è½ãå®è£ ãã¾ããPCãã©ã¦ã¶ãªã©ã§ç¾å¨å°ãåå¾ã§ããªãã£ãå ´åã¯æ¥æ¬ã¸ãå ¬åï¼æ³¨1ï¼ã表示ãã¾ãã
- èµ·åããã¨ãç¾å¨å°ãåå¾ãã¦å°å³ã表示
- å°å³ä¸ã§ç®çå°ãã¿ããããã¨ãç¾å¨å°ããç®çå°ã¾ã§ã®ã«ã¼ããç·è·é¢ãç·æéãç¾å¨å°ã¨ç®çå°ã®ä½æã表示
- å°å³ãå度ã¿ããããã¨ãç®çå°ãå¤æ´ããç¾å¨å°ãå度åå¾ãã¦æ°ããã«ã¼ãã¨é¢é£æ å ±ã表示
- ã«ã¼ãã表示ããå°å³ä¸ã«ç¾å¨ã®é¨é²ã®ç¶æ ãéãã¦è¡¨ç¤º
ãæ¥æ¬ã¸ãå ¬åã¯å µåº«ç西èå¸ä¸æ¯å»¶çºã«ããå ¬åã§ãæ±çµ135度ãåç·¯35度ã«ä½ç½®ãã¦ãããæ¥æ¬ã¯æ±çµ123度ï½147度ãåç·¯24度ï½46度ã®æ ã«åã¾ã£ã¦ããã®ã§ãæ±çµ135度ãåç·¯35度ã®ãã®å°ç¹ãã¾ãã«æ¥æ¬ã®ä¸å¿ã§ãã“ã¸ã”ã ã¨ãããã¨ã§ãã
éçºç°å¢ã®æºå
ã¢ããªã±ã¼ã·ã§ã³IDã®ç»é²
ãããã¾ã§ã®è¨äºã§ãæ¸ããã¦ãã¾ãããYOLPã§æä¾ããã¦ããAPIãå©ç¨ããããã«ã¯ã¢ããªã±ã¼ã·ã§ã³IDãå¿ è¦ã«ãªãã¾ãããã§ã«ã¢ããªã±ã¼ã·ã§ã³IDããæã¡ã®æ¹ã¯ãã¡ããå©ç¨ãã¦ããã ããã¢ããªã±ã¼ã·ã§ã³IDããæã¡ã§ãªãæ¹ãæ°ããã¢ããªã±ã¼ã·ã§ã³IDã®ç»é²ãå¸æããæ¹ã¯ã以ä¸ã®ãã¼ã¸ãåèã«ã¢ããªã±ã¼ã·ã§ã³IDãç»é²ãã¦ãã ããã
ããªããã¢ããªã±ã¼ã·ã§ã³IDãç»é²ããããã«ã¯ãYahoo! JAPAN IDã§ãã°ã¤ã³ããå¿ è¦ãããã¾ãã
ãã«ã¼ãé¨é²ãã§ãã«ã¼ãã½ã¼ã¹ã³ã¼ã
ãä»åã®Webã¢ããªãã«ã¼ãé¨é²ãã§ãã«ã¼ãã®ã½ã¼ã¹ã³ã¼ãã¯ä»¥ä¸ã®ã¨ããã§ãã
ãåè¿°ã®ã¨ããã<ããªãã®ã¢ããªã±ã¼ã·ã§ã³ID>ã®é¨åã¯ãèªèº«ã§åå¾ãããã¢ããªã±ã¼ã·ã§ã³IDã«æ¸ãæãã¦ãã ããã
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <title>ã«ã¼ãé¨é²ãã§ãã«ã¼</title> <style type="text/css"> html, body { width:100%; height:100%; } html, body, div{ margin:0; padding:0; } div#label{ z-index:2; padding:8px; overflow:hidden; color: #fff; background-color: #000; background-image: -webkit-gradient( linear, 0% 0%, 0% 100%, from(rgba(155, 155, 155, 0.1)), to(rgba(255, 255, 255, 0.5)), color-stop(.5,rgba(155, 155, 155, 0.2)), color-stop(.5,rgba(255, 255, 255, 0.1)) ); border-radius: 8px; opacity: .7; } div#title{ font-size:14pt; font-weight:bold; line-height:1.2em; width:100%; overflow:hidden; } div#cur, div#dst{ font-size:10pt; font-weight:normal; line-height:10pt; overflow:hidden; } div#summary{ font-size:12pt; font-weight:bold; line-height:12pt; overflow:hidden; } </style> <script src="http://js.api.olp.yahooapis.jp/OpenLocalPlatform/V1/jsapi?appid=<ããªãã®ã¢ããªã±ã¼ã·ã§ã³ID>"></script> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> window.onload = function() { // å°å³è¡¨ç¤º var map = new Y.Map('map', { configure : { scrollWheelZoom : true, weatherOverlay: true // é¨é²ã¬ã¼ãã¼ON } }); map.drawMap(new Y.LatLng(35, 135), 15, Y.LayerSetId.NORMAL); map.addControl(new Y.ZoomControl()); //å§ç¹ã¯ Geolocation API ã使ã£ã¦ç¾å¨å°ãåå¾ var start = new Y.LatLng(35, 135); // å§ç¹ var end; // çµç¹ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { start = new Y.LatLng(pos.coords.latitude, pos.coords.longitude); map.panTo(start); }, null, { enableHighAccuracy: true, timeout: 3000, maximumAge: 0 }); } // çµç¹ã¯å°å³ãã¿ãããã¦è¨å® map.bind('click', function(pos) { end = pos; // ç¾å¨å°ãåå¾ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { start = new Y.LatLng(pos.coords.latitude, pos.coords.longitude); createRoute(start, end); }, function() { // åããªãã£ãå ´å createRoute(start, end); }, { enableHighAccuracy: true, timeout: 3000, maximumAge: 0 }); } }); // ã«ã¼ãã表示ããããã®ã¬ã¤ã¤ã¼ãè¨å®ãã var routeSearchLayer = new Y.RouteSearchLayer(); routeSearchLayer.bind('drawend', function(result) { dispRouteInfo(result); }); map.addLayer(routeSearchLayer); // ã«ã¼ãã表示ãã var createRoute = function(s, e) { if (s && e) { routeSearchLayer.clearRoute(); var config = { enableRestrict: true, // 交éè¦å¶ãèæ ®ãã useCar: true, // èªåè»ã使ã useFerry: true // ãã§ãªã¼ã使ç¨ãã }; routeSearchLayer.execute([s, e], config); } } // ã«ã¼ãæ å ±ã表示ãã var dispRouteInfo = function(result) { $('#summary').html('ç·è·é¢' + result.TotalDistance + 'm, ç·æé' + result.TotalTime + 'å'); // å§ç¹ã¨çµç¹ã®ä½æãåå¾ãã¦è¡¨ç¤º var geocoder = new Y.GeoCoder(); geocoder.execute({latlng: start}, function(r) { $('#cur').html('ç¾å¨å° : ' + r.features[0].property.Address); }); geocoder.execute({latlng: end}, function(r) { $('#dst').html('ç®çå° : ' + r.features[0].property.Address); }); } // ãªãµã¤ãº(å転)ã®æã«å°å³æ´æ° $(window).resize(function() { map.updateSize(); }); } </script> </head> <body> <div id="map" style="width:100%; height:100%;"></div> <div id="label" style="position:absolute; bottom:4px; right:4px; width:64%; height:64px"> <div id="title">ã«ã¼ãé¨é²ãã§ãã«ã¼</div> <div id="cur">ç¾å¨å° : </div> <div id="dst">å°å³ãã¿ãããã¦ç®çå°ãè¨å®ãã¦ãã ãã</div> <div id="summary"></div> </div> </body> </html>ã
ãä¸è¨ã½ã¼ã¹ã³ã¼ãã¯ãGitHubãããã¦ã³ãã¼ããå¯è½ã§ãã
ãã¾ããã³ã¼ããç°¡æ½ã«è¨è¿°ããããã«ãjQuery ãå©ç¨ãã¦ãã¾ããjQueryã®è©³ããä»æ§ã«ã¤ãã¦ã¯http://jquery.com/ãªã©ãåèã«ãã¦ãã ããã
ãã§ã¯æ¬¡é ããåãã¼ãã®è§£èª¬ããã¦ããã¾ãã