some platforms. • e.g. iOS(Objective-C, Swift), Android(Java), Web Service(JavaScript) • This time we will use the API using JavaScript. • We can embed a map very easily on my web page. • We can create map own favorite maps, including displaying markers ,lines and circle on the map, and it is very useful. My web page API Google Map Structure ① Want map ② Request map data ③ Response map data ④ Show map 4
element(Base Code) <body> <div> <strong>Sample</strong> </div> <div id="map"></div> <script type="text/javascript"> var latlng = new google.maps.LatLng(34.7245225, 137.7177968); var options = { zoom: 15, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map'), options); // Add code that I introduce next page in following </script> </body> 9
Add this to Base Code. <script type="text/javascript"> ・・・ var map = new google.maps.Map(document.getElementById('map'), options); var latlng = new google.maps.LatLng(34.7245225, 137.7177968); var marker = new google.maps.Marker({ position: latlng, map: map }); var latlng_castle = new google.maps.LatLng(34.7117718, 137.7248914); var marker_castle = new google.maps.Marker({ position: latlng_castle, map: map }); </script> Add 11
Add this to Base Code. <script type="text/javascript"> ・・・ var map = new google.maps.Map(document.getElementById('map'), options); latlng = new google.maps.LatLng(34.7245225, 137.7177968); latlng_catsle = new google.maps.LatLng(34.7117718, 137.7248914); var points = [ latlng, latlng_catsle ]; var line = new google.maps.Polyline({ path: points, map: map }); </script> Add 13
Add this to Base Code. <script type="text/javascript"> ・・・ var map = new google.maps.Map(document.getElementById('map'), options); var popCircle = new google.maps.Circle({ map: map, center: latlng_mid, radius: 300 }); </script> Add 15
is supplied by U.S. forces. • Russia is using an original satellite, such GPS satellite. It is called GLONAS. • Japan is launching a satellite to aid GPS. It is called QZSS, Common name is “Michibiki(みちびき)” • GPS measures the position on the earth using the difference in distance from three or more satellites. 16
a file into JavaScript, use the FileReader() object. function gpx_load(){ var file = document.getElementById("filePicker").files[0]; var reader = new FileReader(); reader.addEventListener('load', parseXML, false); reader.readAsText(file); function parseXML(e){ ・・・ } } 26
.gpx files with JavaScript, you need to be able to do DOM manipulation with an XML parser. function parseXML(e){ 'use strict'; var xml = e.target.result; var parser = new DOMParser(); var dom = parser.parseFromString(xml, 'text/xml'); ・・・ } 27
for (var i = 0; i < wpt.length; i++) { var lat_wpt = wpt[i].getAttribute('lat'); var lon_wpt = wpt[i].getAttribute('lon'); var latlng_wpt = new google.maps.LatLng(lat_wpt, lon_wpt); var marker_wpt = new google.maps.Marker({ position: latlng_wpt, map: map }); } 28
var points = []; for (var i = 0; i < trkpt.length; i++) { var lat_trkpt = trkpt[i].getAttribute('lat'); var lon_trkpt = trkpt[i].getAttribute('lon'); var p = new google.maps.LatLng(lat_trkpt, lon_trkpt); points.push(p); } var line = new google.maps.Polyline({ path: points, map: map }); 29