worklight混合应用程序不会要求分享您的位置。没有问它是否显示其他位置。我能为此做些什么?请告诉我解决方案。
这是我的总代码
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Go2needs</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
window.$ = window.jQuery = WLJQ;
function wlCommonInit() {
}
function getGeo() {
alert();
/* WL.Device.Geo.acquirePosition(positive, negative, {
enableHighAccuracy: true,
});
alert(); */
if (navigator.geolocation) {
alert('if');
navigator.geolocation.getCurrentPosition(function(position) {
//alert(position.coords.latitude);
//alert(position.coords.longitude);
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
geocoder.geocode({
'latLng': latlng
}, function(results, status) {
alert('geo');
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1]);
alert(results[1].formatted_address);
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
alert('end');
}
}
/* function positive(data) {
alert();
alert(JSON.stringify(data));
}
function negativa(data) {
alert();
alert(JSON.stringify(data));
} */
</script>
</head>
<body onload="WL.Client.init({})">
<input type="button" value="Click" onclick="getGeo()" />
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
</html>
答案 0 :(得分:1)
你实现这个的方式很奇怪;就好像你正在关注Worklight 4.x或5.x的教程......很老。
试试这个:
<强>的AndroidManifest.xml 强>
添加所需权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<强>的index.html 强>
head
应该是这样的:
<head>
<meta charset="UTF-8">
<title>index</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<!-- <link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png"> -->
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
body
:
<body style="display: none;">
<h1>Googlel Maps - show my position</h1>
<div id="map-canvas"></div>
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
<强> main.js:强>
var myLat;
var myLong;
function wlCommonInit(){
navigator.geolocation.getCurrentPosition(setPositionCoords, errorSettingCoords);
var mapOptions = {
center: new google.maps.LatLng(myLat, myLong),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(myLat, myLong),
map: map,
title:"Hey Me!"
});
}
function setPositionCoords(position) {
myLat = position.coords.latitude;
myLong = position.coords.longitude;
}
function errorSettingCoords() {
alert ("Failed setting coordinates.");
}