java - 使用 Google Map Api v2 的 Android onLocationChanged with Direction

标签 java android google-maps google-maps-android-api-2

我正在使用 Google Map Markers 和 Polylines 为 Android 制作旅游 map ,我成功地做到了这一点,但现在我需要添加一些可以使我的应用程序对用户更友好的东西。所以我想把这个功能放到我的应用程序中。

类似的东西。

enter image description here

当用户移动时实时更新。

无论如何这是我的应用

enter image description here

我不知道如何开始放置方向。谁能帮帮我?

尝试过使用这种方法,但我失败了。

` @覆盖 public void onLocationChanged(位置位置){ //获取当前位置的纬度 双纬度 = location.getLatitude();

    // Getting longitude of the current location
    double longitude = location.getLongitude();

    // Creating a LatLng object for the current location
    LatLng latLng = new LatLng(latitude, longitude);

    // Showing the current location in Google Map
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

    // Zoom in the Google Map
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(18));



    start = latLng;

    Log.d("Location Changed: ", latLng.toString());
    //etLog.append("Location Changed: " + latLng.toString() + System.getProperty("line.separator"));
}

`

最佳答案

尝试使用此代码,您将在 map 上实时获得更新的位置。

public class MapActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener,LocationListener{ 
final String TAG = "mapactivity";
LocationRequest  locationRequest;
GoogleAPiClient googleApiClient;
googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();
@Override
public void onStart(){
    super.onStart();
    googleApiClient.connect();
}
@Override
public void onStop(){
    googleApiClient.disconnect();
    super.onStop();
}
@Override
public void onConnectionSuspended(int i){
    Log.i(TAG, "Connection suspended");

}
@Override
public void onConnectionFailed(ConnectionResult connectionResult){
    Log.i(TAG, "connection failed");

}
@Override
public void onConnected(Bundle bundle){
    locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(1000);
    LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
@Override
public void onLocationChanged(Location location){
    Double curLat = location.getLatitude();//current latitude
    Double curLong = location.getLongitude();//current longitude
} }

关于java - 使用 Google Map Api v2 的 Android onLocationChanged with Direction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34304279/

相关文章:

java - 正则表达式查找整个单词

android - FlatList 或 ListView 上的 [react-native]onPanResponderRelease 不会在 android 中触发

php - 如何在实时服务器中执行 json 解码?

java - Jar 文件 - 防止访问源代码

java - 从 Android 扬声器播放声音

android - 使用 LiveData、协程和事务测试 Android Room

php - 标记未显示在 map 上

java - 使用 mysql、google map 进行 Web 应用程序所需的提示,

java - 客户端/服务器套接字 Java(模式 MVC)未向客户端发送正确的信息

Android ndk找不到atof函数