tag:blogger.com,1999:blog-8597268330337687963.post4611084913330254151..comments2023-05-08T05:16:54.815-07:00Comments on Brendan's Compendium: Adding and removing GeoFences to a Google MapUnknownnoreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8597268330337687963.post-29872844720720680682018-08-04T00:32:38.991-07:002018-08-04T00:32:38.991-07:00This is helpful post and important tips at this po...This is helpful post and important tips at this post, It's a very uncommon topics i helpful us at this post..!Anonymoushttps://www.blogger.com/profile/18201245059664904038noreply@blogger.comtag:blogger.com,1999:blog-8597268330337687963.post-7532932227111357702018-04-23T21:23:15.868-07:002018-04-23T21:23:15.868-07:00Hi Adnan,
Yes there is a way to delete any of the ...Hi Adnan,<br />Yes there is a way to delete any of the geofences. I dug into this code that I have not touched in a couple of years to get some answers for you.<br /><br />What I did is create a new class that implements Geofence. I then gave that new class a String instance variable called "requestId", which stores the unique ID of each fence.<br />I also gave this new class a Marker and Circle instance variables to keep track of the fence's circle and marker that I put on my map, but you may not need to do this.<br /><br />Then, create a method that will remove a single fence. This method should take a String requestId as a parameter. Iterate through all your geofences using a for-loop and check their requestId until you find one that matches the requestId passed to the method. Save the index of the fence you want to remove.<br /><br />Now call .get() on your list of geofences and pass it the index of the fence you want to remove. Save the fence returned by get() in a variable: <br />MyGeofence fenceToRemove = myGeofences.get(fenceToRemoveIndex);<br /><br />Then remove it from the list of fences:<br />myGeofences.remove(fenceToRemoveIndex);<br /><br />Then remove its circle and marker from the map, this may be optional for you:<br />fenceToRemove.getCircle().remove();<br />fenceToRemove.getMarker().remove();<br /><br />If this fence has a pending intent, you must also remove that:<br />String geoFenceRequestIdToRemove = fenceToRemove.getRequestId();<br />//Remove from mGeofencePendingIntent<br />List geoFenceToRemove = new ArrayList<>();<br />geoFenceToRemove.add(geoFenceRequestIdToRemove);<br />if (mGeofencePendingIntent != null) { LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient,<br />geoFenceToRemove).setResultCallback(this);<br />} else {<br /> Log.d(TAG, "removeSelectedGeofence - GeoFence pending intent is null.");<br />}<br /><br />Hopefully this helps!Bhttps://www.blogger.com/profile/16589118577475387438noreply@blogger.comtag:blogger.com,1999:blog-8597268330337687963.post-84539100499976053732018-04-23T02:56:52.565-07:002018-04-23T02:56:52.565-07:00Lets assume i had created 10 geofences on the map....Lets assume i had created 10 geofences on the map. Is there any way to delete the fifth geofence? <br />I am not sure if i got your point but it seems from your answer that we can either delete all the geofences or just the one that is added at the end.<br />I would really appreciate your answer if u do so Anonymoushttps://www.blogger.com/profile/08552327575013676102noreply@blogger.com