Chap 4. Geolocation API.

Slides:



Advertisements
Similar presentations
Members: Twinkle Agarwal Anjana Bhirde Ravi Madaiah David Hodgson Instructor: Dr. Perez Davila Mentor: Mr. Todd Guillory.
Advertisements

Location based services
HTML 5 – GeoLocation and Maps. Geolocation API What is a ”geolocation”…? A geographical location, defined in terms of – Latitude (north/south) – Longitude.
Google Maps API L. Grewe. Google Maps Largest Mapping API One of the most popular web services Used in many web “mashup” applications Used on many platforms.
Lines and Polygons Peterson. Simple Line function initialize() { var myLatLng = new google.maps.LatLng(5, -170); var myOptions = { zoom: 2, center: myLatLng,
Geo Using a device’s location as an input. Why Because the user might not know where they are Because typing is the worst on small devices.
CHAPTER 26 CREATING LOCATION-AWARE WEBPAGES USING GEOLOCATION.
WorldFireAlarm Version 1.1 iPhone, iPad Application Aratos Technologies S.A.
HTML5. What is HTML5? HTML5 will be the new standard for HTML. HTML5 is the next generation of HTML. HTML5 is still a work in progress. However, the major.
HTML5 GEOLOCATION AND SHAREPOINT GEOLOCATION What is Geolocation? How easy it is to use this service? Can we do something without Javascript?
CHAP 4. GEOLOCATION API.  You can request users to share their location and, if they agree, you can provide them with instructions on how to get to a.
UNIT 10 LINKS AND GEOLOCATION. OBJECTIVES  CO1 Describe various components of the Open Web Platform.  CO2 Create a website using HTML5.  CO3 Create.
Location-Based API 1. 2 Location-Based Services or LBS allow software to obtain the phone's current location. This includes location obtained from the.
Programming Games Recap on Google Maps. Creating elements. Dynamic creation of elements (multiple video elements). Geolocation. Classwork/Homework: Catch-up.
Location based services Using Google Maps v2 etc. in Android apps 1Location based services.
Social Media. Behavioral Marketing General themes. Cookies. Geolocation. Homework: check out cookies on your computer. Experiment with geolocation.
Programming games Examples: Audio example. Google Maps api. Classwork: show more complex video. Classwork/Homework: Find place (lat and long) for basic.
Google Maps API. Static Maps send an HTTP GET request receive an image (PNG, GIF, JPEG) no javascript needed encode params in URL example:
INTRODUCTION TO HTML5 Geolocation. Display a Specific Location with Google Maps  You can use the Google Maps API to display a custom map on your own.
Android - Project Green basket Android Application * Let's you do your grocery shopping location based. * Let's you decide to go to the closest grocery.
Programming Games Google Map API examples. CSS. Classwork/homework: Catch up. Upload work. Show your [more] complex Google Maps API example. Plan your.
Proglan Session 1. .  HTML5 will be the new standard for HTML.  The previous version of HTML, HTML 4.01, came in The web has changed a lot since.
Campus Tour COMP 523 Midterm Presentation Justin, Paul, Florian.
How data rule the world Kristoffer Benjaminsson CTO.
Programming Games Reprise: storage, datatypes. Geolocation/Google API example. Work session Homework: [Catch up. Upload work. Post proposal.] Work on your.
Session: 19. © Aptech Ltd. 2HTML5 Geolocation and APIs / Session 19  Explain geolocation and its use in HTML5  Explain the Google Maps API  Explain.
Browser Wars (Click on the logo to see the performance)
Creating Interfaces Show form validation examples, Hangman. HTML5 with Google Maps API. Add in localStorage. Design pitfalls. Homework: Make proposal for.
Static Locations, Dynamic Content.
Phonegap Bridge – Device, Network, Console, Geolocation API’s CIS 136 Building Mobile Apps 1.
Internet Browser Setting Nov SyncSCM Team. 1. Internet Explorer(9 or 10) 2. Google Chrome Agenda.
RIA Geo Location. Finding Location modern devices can get location coordinates phones and tablets can use GPS desktops and laptops –often cannot use GPS.
Rich Internet Applications 9. HTML 5 and RIAs. HTML 5 Standard currently under development by W3C Aims to improve the language with support for the latest.
JavaScript, Sixth Edition
What is HTML5? HTML5 will be the new standard for HTML. The previous version of HTML, HTML 4.01, came in The web has changed a lot since then. HTML5.
Phonegap Bridge –Geolocation and Google maps CIS 136 Building Mobile Apps 1.
Lecture 9: Extra Features and Web Design Tarik Booker CS 120 California State University, Los Angeles.
Industry case study: Data Eric Brumer 2/19/2014. Agenda Belltower Books Belltower Books Trucking: backend & frontend Google maps & javascript.
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
Google Maps API. Contents: 1. Google Maps API Key 2. Create a Basic Google Map 3. Google Maps Overlays 4. Google Maps Events 5. Google Maps Controls 6.
1 Bus Tracker A Google Maps Application. 22 Objectives You will be able to Add an icon to a map created with the Google Maps API. Use Ajax techniques.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Presented by: Lihi Yahav Alexander Isenshtat Supervisor: Kfir Lev-Ari Accessible Navigation.
Google Maps API v3: Built First for Mobile Susannah Raub Google June 24, 2010.
How to fix Netflix Signing In Issues? For More Details Visit Our Website
Mobile Computing CSE 40814/60814 Spring 2017.
Computer network Ch.5.
ISC440: Web Programming 2 Web APIs Google Maps API
UCF Parking Route and Heat Maps
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
Web Services application that operates over a network
HTML5 – The Saga Continues
CHAPTER 9 APIS. CHAPTER 9 APIS WHAT IS AN API?
Tracking and Booking Taxi
Geolocation using Google maps
Sensors, maps and fragments:
Mobile Computing CSE 40814/60814 Spring 2018.
JavaScript: Array, Loop, Data File
HTML5 Geolocation 11/12/2018 Copyright © Carl M. Burnett.
Browser Support for HTML5
Geolocation using Google maps
HTML Level II (CyberAdvantage)
Session V HTML5 APIs - HTML5 Geolocation
Windows Summit /4/2018 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be.
JavaScript Programming Labs
Summary AutoMap™ is an innovative vehicle tracking and reporting system that ensures the vehicle’s location and status. Reduces Cost Removes all routine.
Presented by Ignas Šeškauskas
CS378 - Mobile Computing Location and Maps.
Device,Network, Vibration, Console, Accelerometer
Geolocation using Google maps
Presentation transcript:

Chap 4. Geolocation API

About Location Information You can request users to share their location and, if they agree, you can provide them with instructions on how to get to a nearby store to pick up a new pair of shoes at a discounted rate. The position is provided to the browser by the underlying device (for example, a laptop or a mobile phone) on which the HTML5 Geolocation–enabled browser is running. IP Address Global Positioning System (GPS) Wi-Fi with MAC addresses from RFID, Wi-Fi, and Bluetooth GSM or CDMA cell phone IDs Geolocation API Removed from Unsecured Origins in Chrome 50

The pros and cons of geolocation data GPS Very accurate Take a long time, can drain a user’s device’s batteries Does not work well indoors May require additional hardware Wi-Fi Accurate Works indoors Fix quickly & cheaply Not good in rural areas with few wireless access points Cell Phone Fairly accurate Requires a device with access to a cell phone or cell modem Not good in rural areas with fewer cell phone towers User-Defined May have more accurate location data Allows services for alternate locations User entry might be faster than detection Can also be very inaccurate, especially if the location changes

Arachitecture & Privacy The browser intercepts and requests user permission at step 2.

Browser Support Browser support for HTML5 Geolocation Browser Details Chrome Supported in Google Chrome version 2 with Gears Firefox Supported in version 3.5 and greater Internet Explorer Supported via the Gears plugin Opera Planned support version 10, experimental support in nightly builds Safari Supported in version 4 for the iPhone

Checking for Browser Support if(navigator.geolocation) { document.getElementById("support").innerHTML = "HTML5 Geolocation supported."; } else { document.getElementById("support").innerHTML = "HTML5 Geolocation is not supported in your browser."; }

Positions requests Theres are two type of position requests One-shot position request Repeated position updates

One-Shot Position Requests Usage void getCurrentPosition(in PositionCallback successCallback, in optional PositionErrorCallback errorCallback, in optional PositionOptions options); Example navigator.geolocation.getCurrentPosition(updateLocation, handleLocationError, {timeout:10000}); updateLocation is a PositionCallback function will implement later handleLocationError is a PositionErrorCallback function will implement later

Implement Position Callback function updateLocation(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; var accuracy = position.coords.accuracy; document.getElementById("latitude").innerHTML = latitude; document.getElementById("longitude").innerHTML = longitude; document.getElementById(“accuracy”).innerHTML = “This location is accurate within “ + accuracy + “ meters.” }

Implement Position Error Callback function handleLocationError(error) { switch(error.code) { case 0: updateStatus(“Retrieving location error: " + error.message); break; case 1: updateStatus("The user prevented retrieving location."); case 2: updateStatus(“Unable to determine your location: " + error.message); case 3: updateStatus(“Retrieving timed."); }

REPEAT Position updates Usage long watchPosition(in PositionCallback successCallback, in optional PositionErrorCallback errorCallback, in optional PositionOptions options); Example navigator.geolocation.watchPosition(updateLocation, handleLocationError); updateLocation is a PositionCallback function same as getCurrentPosition implemented above. handleLocationError is a PositionErrorCallback function same as getCurrentPosition implemented above.

Cancel position updates Usage navigator.geolocation.clearWatch(watchId); Example var watchId = navigator.geolocation.watchPosition(updateLocation, handleLocationError);

Show me on a google map Require Google Map JavaScript API <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script> Put Div for Google Map <div id="map_canvas" style="width: 500px; height: 500px;"></div>

Show me on a google map (Cont.) Google Map Example var map; function initialize() { var div = document.getElementById('map_canvas'); map = new google.maps.Map(div, {zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP}); navigator.geolocation.getCurrentPosition( function(pos) { var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude); var infowindow = new google.maps.InfoWindow({ map: map, position: latlng, content: 'Location found using HTML5.‘ }); map.setCenter(latlng); }, function(error) { alert('Cannot get Location data: ' + error.code); } ); } window.addEventListener("load", initialize, true); 加入 InfoWindow 設定地圖中心點

Longitude And Latitude

Get Distance between locations // 用 Haversine 公式計算距離 function getDistance(lat1, lon1, lat2, lon2) { // 角度轉徑度 function Deg2Rad(deg) { return deg * Math.PI / 180; } lat1 = Deg2Rad(lat1); lat2 = Deg2Rad(lat2); lon1 = Deg2Rad(lon1); lon2 = Deg2Rad(lon2); var R = 6371; // km var x = (lon2 - lon1) * Math.cos((lat1 + lat2) / 2); var y = (lat2 - lat1); var d = Math.sqrt(x * x + y * y) * R; return d;

Get Nearest Locations var pois = [ ["台北", 25.0329636, 121.5654268], ["台中", 24.1477358, 120.6736482], ["台南", 22.99793, 120.2126007], ["台東", 22.7972447, 121.0713702] ]; function getNearestCity(latitude, longitude) { var mindif = 99999; var closest; for (index = 0; index < pois.length; ++index) { var dif = getDistance(latitude, longitude, pois[index][1], pois[index][2]); if (dif < mindif) { closest = index; mindif = dif; } // echo the nearest city alert(pois[closest]);

Drawing MARKER var latlng = new google.maps.LatLng(lat, lng); var marker = new google.maps.Marker({ position: latlng, map: map });

Drawing Route var firstCord = {lat: 25.0329636, lng: 121.5654268}; var secondCord = {lat: 24.1477358, lng: 120.6736482}; var coordinates = [firstCord, secondCord]; var routePath = new google.maps.Polyline({ path: coordinates, geodesic: true, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); routePath.setMap(map);

Google map event google.maps.event.addListener(map, 'click', function (event) { var myLatLng = event.latLng; var lat = myLatLng.lat(); var lng = myLatLng.lng(); addMarker(lat, lng); pois.push(["Position Name", lat, lng]); }); 取得點選的經度/緯度

exercise: Drawing Nearest Marker