开发者

GPS doesnt' work (Android web application)

I'm writing web application for mobile phones and I need to use geolocation.

I wrote: (javascript)

function GeoLocationStart(){
    if(navigator.geolocation){
               navigator.geolocation.getCurrentPosition(onSuccess,onError);
            }
            else{
               alert("Functionality not available");
            }
}

function onSuccess(position) {
    var initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
    map.setCenter(initialLocation);
    var userMarker = new google.maps.Marker({
          position: initialLocation,
          map: map,
          title: "You're here",
          icon: face
        });     
    userMarker.setMap(map);

    var userhtml = "It's you!";
    var UserInfoWindow = new google.maps.InfoWindow({content: userhtml});   

    google.maps.event.addListener(userMarker, 'click', function() {     
            UserInfoWindow.open(map, userMarker);
          });
};

function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

It works fine but without GPS.

Though I set in Android manifest file permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<u开发者_StackOverflow中文版ses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

app doesn't start even searching sattelites. (Of course I checked GPS on my phone, it works in other applications)

How to switch GPS on?

Thanks


I found a solution.

After location had found using wireless network, GPS stopped to work because the goal has been achieved - location is defined!

To continue searching position I wrote

var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { frequency: 3000 });

so GPS launched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜