在安卓中向地图添加标记



我有一个 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 中每个标记的信息(如果它们在用户的特定距离内),然后将标记添加到地图上。

检查此行

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);
}

相关内容

  • 没有找到相关文章

最新更新