【发布时间】:2021-08-26 01:43:03
【问题描述】:
这是用来制作折线的
for (int j = 0; j < user.length(); j++) {
JSONObject routes = user.getJSONObject(j);
JSONArray rute = routes.getJSONArray("points");
PolylineOptions options = new PolylineOptions();
for (int k = 0; k < rute.length(); k++) {
JSONObject users = rute.getJSONObject(k);
double rutes = users.getDouble("latitude");
double rutess = users.getDouble("longitude");
options.color(Color.parseColor("#FFA866"));
options.width(10);
options.geodesic(true);
options.add(new LatLng(rutes, rutess));
Log.d("TAG", "Hasil latitude = " + rutes);
Log.d("TAG", "Hasil longtitude = " + rutess);
jumlah_klik = jumlah_klik + 1;
}
polyline_bis = mMap.addPolyline(options);
}
这是用于删除折线
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (polyline_bis != null){
polyline_bis.remove();
}else {
Log.d("TAG","not removee");
}
return true;
}
});
这是初始化地图片段
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
mapView = mapFragment.getView();
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(SearchDanBisKlik.this);
Places.initialize(SearchDanBisKlik.this, getString(R.string.api_key));
placesClient = Places.createClient(this);
这是在 GoogleMap googleMap 初始化
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
问题是: 单击标记时无法删除折线,如何删除?帮帮我,谢谢。
【问题讨论】:
标签: android android-studio google-maps maps