onlocationchanged函数从未调用 - > PhoneGap的

时间:2013-01-07 12:34:38

标签: java javascript android html5 cordova

我有一个用HTML5编写并包含在PhoneGap中的应用程序。

我在应用程序上有一张地图,我想通过GPS查找用户的位置。

我尝试了以下方式:

在JS中我有一个改变标记位置的函数:

function GPS(lat, lon) {
    alert('Now U move');
    var CurrentPosition = new google.maps.LatLng(lat, lon);
    markerMyLoc.setPosition(CurrentPosition);
}

在Java中,我有关注位置的函数并发送JS函数:

public class MainActivity extends DroidGap {

private LocationManager locationManager;
private LocationListener locationListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setIntegerProperty("splashscreen", R.drawable.splash);
    super.loadUrl("file:///android_asset/www/XXX.html", 10000);

     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  

     locationListener = new GPSLocationListener();

      locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 
        0, 
        0, 
        locationListener);

    } 
}

GPSLocationListener类:

public class GPSLocationListener implements LocationListener 
{
  @Override
  public void onLocationChanged(Location location) {
    if (location != null) {
        GPScls MyGPS= new GPScls();
        MyGPS.GPS(location.getLatitude(),location.getLongitude());
    }
  }

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}
}

GPScls课程:

public class GPScls extends DroidGap {
    public void GPS(double latitude,double longitude) {
        super.loadUrl("javascript:GPS("+latitude+","+longitude+")");
    }
}

警报:alert('Now U move');未显示,有人可以帮我解决此问题吗?

1 个答案:

答案 0 :(得分:0)

我意识到,我没有足够的回复GPS的答案

请看以下问题:

Is the function onLocationChanged called every movement of Android device?