Android 我没有';在我的碎片里找不到蓝线的方向
**此代码将在Android 我没有';在我的碎片里找不到蓝线的方向,android,Android,**此代码将在两点之间绘制一条路径。代码中给出了这一点。我试了很多次,但都没有找到路线。我为多段线添加了code,但它没有绘制它** @Override public void onLocationChanged(Location location) { mLastLocation = location; if (mCurrLocationMarker != null) {
两点之间绘制一条路径。代码中给出了这一点。我试了很多次,但都没有找到路线。我为多段线添加了code
,但它没有绘制它**
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
// markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.source_pin));mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
Log.d("Current", "" + mCurrLocationMarker);
if(first)
{
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,15));
first = false;
}
else{
}
if (latLngDestination!=null) {
markerOptions1 = new MarkerOptions();
markerOptions1.position(latLngDestination);
markerOptions1.title("Destination");
markerOptions1.icon(BitmapDescriptorFactory.fromResource(R.drawable.destination_pin));
mDestinationMarker = mGoogleMap.addMarker(markerOptions1);
Log.d("Destinantion", "" + mDestinationMarker);
}
}
@Override
public void onClick(View v) {
}
@Override
public void onConnected(Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
private String getUrl(LatLng origin, LatLng dest, String directionMode) {
// Origin of route
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
// Destination of route
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
// Mode
String mode = "mode=" + directionMode;
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + mode;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters + "&key=" + getString(R.string.google_api_key);
return url;
}
**以下是在点中添加标记的代码**
@Override
public void onMapReady(final GoogleMap googleMap) {
try {
MapsInitializer.initialize(mContext);
} catch (Exception e) {
e.printStackTrace();
}
mGoogleMap = googleMap;
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
//Initialize Google Play Services
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (ContextCompat.checkSelfPermission(mContext,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
//Location Permission already granted
buildGoogleApiClient();
mGoogleMap.setMyLocationEnabled(true);
} else {
//Request Location Permission
checkLocationPermission();
}
} else {
buildGoogleApiClient();
mGoogleMap.setMyLocationEnabled(true);
}
try {
mGoogleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
}
});
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;