Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / experiments / google-maps / map.js
1
2 //thx @elroyjetson for the code example
3
4 // When map page opens get location and display map
5 $('.page-map').live("pagecreate", function() {
6
7         //boston :)
8         var lat = 42.35843,
9                 lng = -71.059773;
10         
11         //try to get GPS coords
12         if( navigator.geolocation ) {
13                         
14                 //redirect function for successful location     
15                 function gpsSuccess(pos){
16                         if( pos.coords ){ 
17                                 lat = pos.coords.latitude;
18                                 lng = pos.coords.longitude;
19                         }
20                         else{
21                                 lat = pos.latitude;
22                                 lng = pos.longitude;
23                         }
24                 }       
25                 
26                 function gpsFail(){
27                         //Geo-location is supported, but we failed to get your coordinates. Workaround here perhaps?
28                 }
29                 
30                 navigator.geolocation.getCurrentPosition(gpsSuccess, gpsFail, {enableHighAccuracy:true, maximumAge: 300000});
31         }
32
33         /*
34         if not supported, you might attempt to use google loader for lat,long
35         $.getScript('http://www.google.com/jsapi?key=YOURAPIKEY',function(){
36                 lat = google.loader.ClientLocation.latitude;
37                 lng = google.loader.ClientLocation.longitude;
38         });                     
39         */
40
41         var latlng = new google.maps.LatLng(lat, lng);
42         var myOptions = {
43                 zoom: 10,
44                 center: latlng,
45                 mapTypeId: google.maps.MapTypeId.ROADMAP
46     };
47     var map = new google.maps.Map(document.getElementById("map-canvas"),myOptions);
48 });