examples/declarative/modelviews/webview/content/Mapping/map.html
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 <html>
       
     2 <head>
       
     3 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
       
     4 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
       
     5 <script type="text/javascript">
       
     6   var geocoder
       
     7   var map
       
     8   function goToLatLng(latlng,bounds) {
       
     9     if (map) {
       
    10         map.setCenter(latlng)
       
    11         map.fitBounds(bounds)
       
    12     } else {
       
    13         var myOptions = {
       
    14           zoom: 8,
       
    15           center: latlng,
       
    16           mapTypeId: google.maps.MapTypeId.ROADMAP
       
    17         };
       
    18         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
       
    19     }
       
    20   }
       
    21   function initialize() {
       
    22     geocoder = new google.maps.Geocoder();
       
    23     if (window.qml.address) {
       
    24         goToAddress()
       
    25     } else {
       
    26         goToLatLng(new google.maps.LatLng(window.qml.lat,window.qml.lng));
       
    27     }
       
    28   }
       
    29   function goToAddress() {
       
    30       if (geocoder) {
       
    31         var req = {
       
    32             address: window.qml.address,
       
    33         }
       
    34         if (map)
       
    35             req.bounds = map.getBounds()
       
    36         window.qml.status = "Loading";
       
    37         geocoder.geocode(req, function(results, status) {
       
    38           if (status == google.maps.GeocoderStatus.OK) {
       
    39             window.qml.status = "Ready";
       
    40             goToLatLng(results[0].geometry.location,results[0].geometry.bounds);
       
    41           } else {
       
    42             window.qml.status = "Error";
       
    43           }
       
    44         });
       
    45       }
       
    46   }
       
    47 </script>
       
    48 </head>
       
    49 <body onload="initialize()" leftmargin="0px" topmargin="0px" marginwidth="0px" marginheight="0px">
       
    50   <div id="map_canvas" style="width:100%; height:100%"></div>
       
    51 </body>
       
    52 </html>