1 / 7

RIA

Geo Location. RIA. 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. Using DOM to Find Location.

jamesdyer
Download Presentation

RIA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geo Location RIA

  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&size=400x300&sensor=false"; document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";

  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; 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

More Related