2

我正在使用cordova 2.0.0,我正在测试android 2.2 我想制作一个应用程序来获取我的地理位置并将其显示在谷歌地图中。现在我尝试了我的代码,当我运行它时,它显示了我的坐标,但是当我单击确定时它没有显示地图。

这些是我的权限:

<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<access origin="http://google.com*" />
<access origin="http://maps.google.com*" /> 
<access origin="https://google.com*"/>
<access origin="https://maps.google.com*"/>

如果有人能告诉我我做错了什么,我将不胜感激。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

     <head>

<meta name="viewport" content="width=device-width; height=device-height; user-scalable=no" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Beer Me</title>
<link rel="stylesheet" href="/master.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript">

function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':10000});

}

//GEOLOCATION
var onSuccess = function(position) {
    alert('Latitude: '  + position.coords.latitude   + '\n' +
          'Longitude: ' + position.coords.longitude  + '\n');

    var myLat = position.coords.latitude;
    var myLong = position.coords.longitude;

    //MAP
    var mapOptions = {
        center: new google.maps.LatLng(myLat, myLong),
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"),
                                  mapOptions);

};

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}


     </script>
     </head>
     <body onload="onLoad()"> 
     <div id="map_canvas" style="width:100%; height:100%"></div>
     </body>
     </html>
4

1 回答 1

1
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

试试这个 src,它适用于我的相同代码!

于 2012-08-07T10:51:32.343 回答