谷歌只映射一次Android API日志数据

谷歌只映射一次Android API日志数据,android,google-maps,google-maps-android-api-2,Android,Google Maps,Google Maps Android Api 2,我正在尝试使用GoogleMapsAPIv2来记录用户的位置,并将其存储到SQLite数据库中。我设法做到了这一点。但现在问题出现了,因为我的位置数据只记录了一次。一旦用户按下一个按钮,该位置应连续记录,直到用户按下另一个按钮。然而,就我而言;应用程序会在用户按下按钮时记录位置,就这样。该位置只记录一次。我曾尝试使用mLocationRequest句柄操纵时间,但更改时间没有任何效果;我的数据只记录了一次。 有人能帮我吗 private void handleNewLocation(Locati

我正在尝试使用GoogleMapsAPIv2来记录用户的位置,并将其存储到SQLite数据库中。我设法做到了这一点。但现在问题出现了,因为我的位置数据只记录了一次。一旦用户按下一个按钮,该位置应连续记录,直到用户按下另一个按钮。然而,就我而言;应用程序会在用户按下按钮时记录位置,就这样。该位置只记录一次。我曾尝试使用mLocationRequest句柄操纵时间,但更改时间没有任何效果;我的数据只记录了一次。 有人能帮我吗

private void handleNewLocation(Location location) {

    String key = "xx";
    double currentLatitude = location.getLatitude();
    double currentLongitude = location.getLongitude();
    LatLng latLng = new LatLng(currentLatitude, currentLongitude);

    Log.d("location", String.valueOf(latLng));
    databaseHandler.enterMapValues( _workOutId,String.valueOf(latLng));
       // Log.d("location new ", String.valueOf(latLng));

    old_longitude = currentLongitude;
    old_latitude = currentLatitude;
}
此函数用于获取新位置。我在OnConnect中调用此命令:

public void onConnected(Bundle bundle) {

    Log.i(TAG, "location services connected");
    location_current = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); //to get last location


    if (location_current == null) { //if last location is null, only then it will request new location
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    } else {
        handleNewLocation(location_current);

    }

}

我删除了onConnected中的if-else。现在它每5秒获取一次位置,因为这是onCreate()中mLocationRequest中指定的时间。这解决了我的问题

我删除了onConnected中的if-else。现在它每5秒获取一次位置,因为这是onCreate()中mLocationRequest中指定的时间。这解决了我的问题

你能分享你的
onLocationChanged
实现吗?public void onLocationChanged(Location){handleNewLocation(Location);}你能分享你的
onLocationChanged
实现吗?public void onLocationChanged(Location){handleNewLocation(Location);}