Akash Patel
Akash Patel

Reputation: 2767

removeMapObject method does not work in android premium HERE SDK 3.2.2

I changed the android premium HERE SDK 3.2.1 to 3.2.2 now i face a problem in clear routes.

for(int i = 0 ; i < list_routes.size() ; i++)
{
    MapRoute mapRoute = new MapRoute(list_routes.get(i).getRoute());
    m_map.removeMapObject(mapRoute);
}

This snippet code works for 3.2.1 but not working in 3.2.2. I replaced jniLibs folder and HERE-sdk jar of 3.2.2 in my project.

Upvotes: 1

Views: 99

Answers (1)

David Leong
David Leong

Reputation: 1762

This should not have worked regardless of 3.2.1 and 3.2.2. It was probably a bug that it even worked before.

Calling new on MapRoute creates a handle to a natively backed object. Your sample code implies you added the MapRoute also in this manner but never kept a handle to them.

Each MapRoute object is unique, and therefore the "new" keyword has no association to any previously added objects.

The correct solution should be:

    // Keep the list of MapRoute Objects.
    List<MapRoute> routes = new ArrayList<MapRoute>();
    for(int i = 0 ; i < list_routes.size() ; i++)
    {
        MapRoute mapRoute = new MapRoute(list_routes.get(i).getRoute());
        routes.add(mapRoute);
        m_map.addMapObject(mapRoute);
    }
    // Later when you want to remove the routes.
    for(int i = 0 ; i < list_routes.size() ; i++)
    {
        m_map.removeMapObject(routes[i]);
    }

Upvotes: 2

Related Questions