1

I am new to both Programming and this community, but can we implements GoogleMaps.Util.PolyUtil - containsLocation method in BroadcastReceiver?

< Reference Only>

I made 2 demo application, the first one is to learn about Polygon (lets call it appsA). AndroidCoding's code as reference https://www.youtube.com/watch?v=_Sx45CbBsoA

the second one is to learn Geofence (appsB). I am using yoursTRULY's code here https://www.youtube.com/watch?v=nmAtMqljH9M&list=PLdHg5T0SNpN3GBUmpGqjiKGMcBaRT2A-m&index=10

< /Reference Only >

Problem:

I am trying to implements containsLocation from appsA... https://i.stack.imgur.com/AlWVo.png where currLoc is the LatLng of the LastLocation and latLngList is the ArrayList of the Polygon.

into BroadcastReceiver in appsB... https://i.stack.imgur.com/GMQvt.png

I've tried searching for the solution about this, but none works/relevant.. I am thinking to pass the ArrayList of the Polygon LatLng into the BroadcastReceiver -> get current location coordinate -> then finally using containsLocation

Here's the code

Initialize variable on MapsActivity

    List<LatLng> latLngList = new ArrayList<>();
    List<Marker> markerList = new ArrayList<>();

MapsActivity

Geofence geofence = geofenceHelper.getGeofence(GEOFENCE_ID, latLng, radius, Geofence.GEOFENCE_TRANSITION_ENTER |
                Geofence.GEOFENCE_TRANSITION_DWELL);
        GeofencingRequest geofencingRequest = geofenceHelper.getGeofencingRequest(geofence);

        PendingIntent pendingIntent = geofenceHelper.getPendingIntent();

GeofenceHelper

    public PendingIntent getPendingIntent(){
        if(pendingIntent!= null){
            return pendingIntent;
        }

        Intent intent = new Intent(this, GeofenceBroadcastReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(this, 2607, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        return pendingIntent;
    }

BroadcastReceiver

        int transitionType = geofencingEvent.getGeofenceTransition();

        switch(transitionType){
            case Geofence.GEOFENCE_TRANSITION_ENTER:
//                it should look like this
//                boolean contains = PolyUtil.containsLocation(currLoc, latLngList, true );
//                if(contains)
                Toast.makeText(context, "GEOFENCE TRANSITION ENTER", Toast.LENGTH_SHORT).show();
                break;

What I want to ask is:

  1. Can I pass an ArrayList into BroadcastReceiver?
  2. Is it possible to do it this way? or is there better solution for this?

Referencing to Marian's answer in Android: Build Polygonal Shape Geofence

Thanks before

0 Answers0