Android的onLocationChanged与方向使用谷歌地图API V2 [英] Android onLocationChanged with Direction using Google Map Api v2

查看:668
本文介绍了Android的onLocationChanged与方向使用谷歌地图API V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与谷歌地图标记和折线Android的旅游地图,我成功地做到了这一点,但现在我需要补充一点,就是可以让我的应用程序更加友好的用户。所以我希望把这个功能给我的应用程序。

I am making a tourist map for android with Google Map Markers and Polylines and I succeeded in doing that but now i need to add something that can make my app more friendly user. so I wanted to put this feature to my app.

类似的东西。

在这里输入的形象描述

使用实时更新,当用户移动。

with live update when the user move.

这好歹我的应用

在这里输入的形象描述

我不知道如何下手上摆放方向。任何人都可以帮我吗?

I don't know how to start on that placing DIRECTION. anyone can help me?

用这个方法尝试,但我失败了。

Tried using this method but i failed.

`
    @覆盖
    公共无效onLocationChanged(地点){
        //获取当前位置的纬度
        双纬度= location.getLatitude();

` @Override public void onLocationChanged(Location location) { // Getting latitude of the current location double latitude = 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"));
}

`

推荐答案

试试这个code,你会得到更新的位置住在地图上。

Try this code you will get updated location live on 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
} }

这篇关于Android的onLocationChanged与方向使用谷歌地图API V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆