0

我有一个HTML5PhoneGap.

我在应用程序上有一张地图,我想通过 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');未显示,谁能帮我解决这个问题?

4

1 回答 1

0

我意识到,我没有足够的努力从 GPS 中返回答案

看下面的问题:

onLocationChanged 函数会调用 Android 设备的每一个动作吗?

于 2013-01-09T11:27:12.750 回答