我正在用谷歌地图标记和Polyline为android制作一个旅游地图,我成功地做到了这一点,但现在我需要添加一些东西,使我的应用程序更友好的用户。所以我想把这个功能放到我的应用程序中。
差不多吧。
当用户移动时,使用实时更新。
不管怎样,这是我的应用程序
我不知道怎么开始那个放置方向。有人能帮我吗?
尝试过使用这种方法,但失败了。
@覆盖公共无效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"));
}
`
发布于 2015-12-15 21:41:24
尝试这段代码,你将得到更新的位置,在地图上直播。
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
} }
发布于 2015-12-15 21:33:57
您必须从google控制台启用google地图方向api。要获得方向,您必须使用api键传递两个latlngs作为源和目的地,您将获得给定源和目标之间的所有点,绘制它们之间的折线,您将得到在源和目的地之间绘制的方向分界线,如屏幕截图所示,请遵循这个链接。
https://stackoverflow.com/questions/34304279
复制