我有一个KML图层,我从输入流中形成如下:
private KmlLayer layer;
inputStream = new URL("urlHERE").openStream();
layer = new KmlLayer(mMap, inputStream, getApplicationContext());
我想遍历此图层中的每个标记,并检查它是否在距我当前位置一定距离内,并且只有在显示时才会显示。
这是我用来获取标记的纬度/长度的代码。
for (KmlPlacemark placemark: layer.getPlacemarks()) {
String s = placemark.getGeometry().getGeometryObject().toString();
Log.d("placemarks",s);
String start = "(";
String end = ")";
String latlngvalue = s.substring(s.indexOf(start)+1,s.lastIndexOf(end));
String[] strngs = latlngvalue.split(",");
double placemarkerLat = Double.parseDouble(strngs[0]);
double placemarkerLong = Double.parseDouble(strngs[2]);
markerLocation.setLatitude(placemarkerLat);
markerLocation.setLongitude(placemarkerLong);
我想要做的是在ArrayList中添加每个Marker的信息,如果它们在用户的特定距离内,然后将标记添加到地图上。
答案 0 :(得分:0)
检查此行
currLocationMarker = mGoogleMap.addMarker(markerOptions); //你的回答
@Override
public void onLocationChanged(Location location) {
mGoogleMap.clear();
mHashMap.clear();
allMarkersLists.clear();
favouriteGpList.clear();
//place marker at current position
//mGoogleMap.clear();
if (currLocationMarker != null) {
currLocationMarker.remove();
}
latitude = location.getLatitude();
longitude = location.getLongitude();
latLng = new LatLng(location.getLatitude(), location.getLongitude());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)).draggable(true);
currLocationMarker = mGoogleMap.addMarker(markerOptions); //YOUR ANSWER HERE
mHashMap.put(currLocationMarker, 0);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(11));
mGoogleMap.setMyLocationEnabled(true);
getMapPin();
//If you only need one location, unregister the listener
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}