Presentation is loading. Please wait.

Presentation is loading. Please wait.

RIA Geo Location. Finding Location modern devices can get location coordinates phones and tablets can use GPS desktops and laptops –often cannot use GPS.

Similar presentations


Presentation on theme: "RIA Geo Location. Finding Location modern devices can get location coordinates phones and tablets can use GPS desktops and laptops –often cannot use GPS."— Presentation transcript:

1 RIA Geo Location

2 Finding Location modern devices can get location coordinates phones and tablets can use GPS desktops and laptops –often cannot use GPS –can get the location of the ISP –not as accurate but better than nothing

3 Using DOM to Find Location navigator.geolocation.getCurrentPosition – asynchronous method that uses callbacks – getCurrentPosition(locFound, locError) – locFound is called if it is successful – locError is called if it is not successful handle errors if location is not supported

4 Example if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(locOK,locErr); } else { document.getElementById("loc").innerHTML= "GEO location is NOT supported"; } function locOK(currPos){ document.getElementById("lat").innerHTML= "Latitude="+currPos.coords.latitude; document.getElementById("lng").innerHTML= "Longitude="+currPos.coords.longitude; } function locErr(e){ document.getElementById("loc").innerHTML= "Error getting current location: "+e.message; }

5 Using Google Map API assign the source of an img tag to the Google URL for making a map just a static image so it does not allow for interaction example: var latlon = position.coords.latitude + "," + position.coords.longitude; var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&si ze=400x300&sensor=false"; document.getElementById("mapholder").innerHTML = " ";

6 Distance Calculation there are sites that can help with calculating the distance between two points using latitude and longitude for example: http://www.movable-type.co.uk/scripts/latlong.html you may need to adjust the units (km vs meters)

7 Sorting Arrays of Objects create a compare function like: function compare(x,y){ if(x.id y.id) return 1; return 0; } then in your code you can use: objs.sort(compare); as long as each object in objs has an id field


Download ppt "RIA Geo Location. Finding Location modern devices can get location coordinates phones and tablets can use GPS desktops and laptops –often cannot use GPS."

Similar presentations


Ads by Google