Adding Overlay to OSMDROID

前端 未结 3 1151
难免孤独
难免孤独 2020-12-14 04:42

I have been struggling with this long time. I am trying to add Overlay on my map. I am using the open source OSMdroid. but all I get by the example is a straight red line fr

3条回答
  •  温柔的废话
    2020-12-14 05:16

    @rayman

    Please one more thing. When there is a change in the location the map does change but the Icon is gone. how do i validate the Icon into the new change? – rayman Jul 1 '11 at 7:12

    this is where your location changes

    public void onLocationChanged(Location location) {
        int lat = (int) (location.getLatitude() * 1E6);
        int lng = (int) (location.getLongitude() * 1E6);
        GeoPoint gpt = new GeoPoint(lat, lng);
        mapController.setCenter(gpt);
        mMapView.invalidate();
    }
    

    But as you can see it does not add new icon to the overlay.

    You should clear the previous items

    items.clear()
    

    (if you want the "old" icon to be removed when the new one is created) and then add the new point (gpt) to the items.

    items.add(new OverlayItem("Title", "Description", gpt));
    

    and so on...

提交回复
热议问题