[英]Adding markers to a map in Android
I have a KML layer which I form from an input Stream as so: 我有一个KML层,我从输入流形成,如下所示:
private KmlLayer layer;
inputStream = new URL("urlHERE").openStream();
layer = new KmlLayer(mMap, inputStream, getApplicationContext());
I want to iterate through each marker in this layer and check if it is within a certain distance to my current location and display it only if it is. 我想遍历这一层中的每个标记,并检查它是否在我当前位置的一定距离内,并且只有在它的情况下才显示它。
This is the code I am using to currently get the lat/long of the markers. 这是我用来获取标记的纬度/长度的代码。
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);
What I want to do is add the information for each Marker in an ArrayList if they are within a certain distance of the user and then add the markers onto the map. 我想要做的是在ArrayList中添加每个Marker的信息(如果它们在用户的特定距离内),然后将标记添加到地图上。
CHECK THIS LINE 检查这条线
currLocationMarker = mGoogleMap.addMarker(markerOptions); currLocationMarker = mGoogleMap.addMarker(markerOptions); //YOUR ANSWER HERE
//你的答案在这里
@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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.