Create and Monitor geofences using polygon shape












0















I am trying to implement a Geofencing system using polygon shape. Basically if an user enters the geofencing region, the user should get a notification. After going through many research i was only able to find Geofence using Circular. So far i implemented the system but it only monitors by circular shape not if someone enters the polygon drawn in the map. If any has done Polygon Geonfencing before please help me out



This is the code i used to draw my polygon



    private void drawGeofence() {
Log.d(TAG, "drawGeofence()");

polyLatLng = new ArrayList<>( );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match last point
polyLatLng.add( new LatLng(6.897287, 79.859544));
polyLatLng.add( new LatLng( 6.905271, 79.862609 ) );
polyLatLng.add( new LatLng( 6.906114, 79.858998 ) );
polyLatLng.add( new LatLng( 6.911808, 79.856206 ) );
polyLatLng.add( new LatLng( 6.912200, 79.851381 ) );
polyLatLng.add( new LatLng( 6.911627, 79.849621 ) );
polyLatLng.add( new LatLng( 6.910965, 79.848073 ) );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match first point

Log.i(TAG, "computeArea " + SphericalUtil.computeArea(polyLatLng));

map.addPolygon(new PolygonOptions()
.addAll(polyLatLng)
.strokeColor(Color.BLACK)
.strokeWidth( 4 )
.fillColor(0x220000FF));
}


Here's my geofence code which track only in circular region



 private static final float GEOFENCE_RADIUS = 1006.3975694699f; // in meters
private void startGeofence() {
Log.i(TAG, "startGeofence()");
if( geoFenceMarker != null ) {

// create geofence
Geofence geofence = createGeofence( 6.904254, 79.853798, GEOFENCE_RADIUS );
GeofencingRequest geofenceRequest = createGeofenceRequest( geofence );
addGeofence( geofenceRequest );
} else {
Log.e(TAG, "Geofence marker is null");
}
}

// Create a Geofence
private Geofence createGeofence( double lat, double lng, float radius ) {
Log.d(TAG, "createGeofence");

return new Geofence.Builder()
.setRequestId(GEOFENCE_REQ_ID)
.setCircularRegion( lat, lng, radius)
.setExpirationDuration( GEO_DURATION )
.setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER
| Geofence.GEOFENCE_TRANSITION_EXIT )
.build();
}enter code here









share|improve this question























  • Possible duplicate of Android: Build Polygonal Shape Geofence

    – Marian Paździoch
    Nov 16 '18 at 9:13











  • I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

    – Waleedh Naim
    Nov 16 '18 at 9:22











  • "geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

    – Marian Paździoch
    Nov 16 '18 at 9:27
















0















I am trying to implement a Geofencing system using polygon shape. Basically if an user enters the geofencing region, the user should get a notification. After going through many research i was only able to find Geofence using Circular. So far i implemented the system but it only monitors by circular shape not if someone enters the polygon drawn in the map. If any has done Polygon Geonfencing before please help me out



This is the code i used to draw my polygon



    private void drawGeofence() {
Log.d(TAG, "drawGeofence()");

polyLatLng = new ArrayList<>( );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match last point
polyLatLng.add( new LatLng(6.897287, 79.859544));
polyLatLng.add( new LatLng( 6.905271, 79.862609 ) );
polyLatLng.add( new LatLng( 6.906114, 79.858998 ) );
polyLatLng.add( new LatLng( 6.911808, 79.856206 ) );
polyLatLng.add( new LatLng( 6.912200, 79.851381 ) );
polyLatLng.add( new LatLng( 6.911627, 79.849621 ) );
polyLatLng.add( new LatLng( 6.910965, 79.848073 ) );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match first point

Log.i(TAG, "computeArea " + SphericalUtil.computeArea(polyLatLng));

map.addPolygon(new PolygonOptions()
.addAll(polyLatLng)
.strokeColor(Color.BLACK)
.strokeWidth( 4 )
.fillColor(0x220000FF));
}


Here's my geofence code which track only in circular region



 private static final float GEOFENCE_RADIUS = 1006.3975694699f; // in meters
private void startGeofence() {
Log.i(TAG, "startGeofence()");
if( geoFenceMarker != null ) {

// create geofence
Geofence geofence = createGeofence( 6.904254, 79.853798, GEOFENCE_RADIUS );
GeofencingRequest geofenceRequest = createGeofenceRequest( geofence );
addGeofence( geofenceRequest );
} else {
Log.e(TAG, "Geofence marker is null");
}
}

// Create a Geofence
private Geofence createGeofence( double lat, double lng, float radius ) {
Log.d(TAG, "createGeofence");

return new Geofence.Builder()
.setRequestId(GEOFENCE_REQ_ID)
.setCircularRegion( lat, lng, radius)
.setExpirationDuration( GEO_DURATION )
.setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER
| Geofence.GEOFENCE_TRANSITION_EXIT )
.build();
}enter code here









share|improve this question























  • Possible duplicate of Android: Build Polygonal Shape Geofence

    – Marian Paździoch
    Nov 16 '18 at 9:13











  • I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

    – Waleedh Naim
    Nov 16 '18 at 9:22











  • "geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

    – Marian Paździoch
    Nov 16 '18 at 9:27














0












0








0








I am trying to implement a Geofencing system using polygon shape. Basically if an user enters the geofencing region, the user should get a notification. After going through many research i was only able to find Geofence using Circular. So far i implemented the system but it only monitors by circular shape not if someone enters the polygon drawn in the map. If any has done Polygon Geonfencing before please help me out



This is the code i used to draw my polygon



    private void drawGeofence() {
Log.d(TAG, "drawGeofence()");

polyLatLng = new ArrayList<>( );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match last point
polyLatLng.add( new LatLng(6.897287, 79.859544));
polyLatLng.add( new LatLng( 6.905271, 79.862609 ) );
polyLatLng.add( new LatLng( 6.906114, 79.858998 ) );
polyLatLng.add( new LatLng( 6.911808, 79.856206 ) );
polyLatLng.add( new LatLng( 6.912200, 79.851381 ) );
polyLatLng.add( new LatLng( 6.911627, 79.849621 ) );
polyLatLng.add( new LatLng( 6.910965, 79.848073 ) );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match first point

Log.i(TAG, "computeArea " + SphericalUtil.computeArea(polyLatLng));

map.addPolygon(new PolygonOptions()
.addAll(polyLatLng)
.strokeColor(Color.BLACK)
.strokeWidth( 4 )
.fillColor(0x220000FF));
}


Here's my geofence code which track only in circular region



 private static final float GEOFENCE_RADIUS = 1006.3975694699f; // in meters
private void startGeofence() {
Log.i(TAG, "startGeofence()");
if( geoFenceMarker != null ) {

// create geofence
Geofence geofence = createGeofence( 6.904254, 79.853798, GEOFENCE_RADIUS );
GeofencingRequest geofenceRequest = createGeofenceRequest( geofence );
addGeofence( geofenceRequest );
} else {
Log.e(TAG, "Geofence marker is null");
}
}

// Create a Geofence
private Geofence createGeofence( double lat, double lng, float radius ) {
Log.d(TAG, "createGeofence");

return new Geofence.Builder()
.setRequestId(GEOFENCE_REQ_ID)
.setCircularRegion( lat, lng, radius)
.setExpirationDuration( GEO_DURATION )
.setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER
| Geofence.GEOFENCE_TRANSITION_EXIT )
.build();
}enter code here









share|improve this question














I am trying to implement a Geofencing system using polygon shape. Basically if an user enters the geofencing region, the user should get a notification. After going through many research i was only able to find Geofence using Circular. So far i implemented the system but it only monitors by circular shape not if someone enters the polygon drawn in the map. If any has done Polygon Geonfencing before please help me out



This is the code i used to draw my polygon



    private void drawGeofence() {
Log.d(TAG, "drawGeofence()");

polyLatLng = new ArrayList<>( );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match last point
polyLatLng.add( new LatLng(6.897287, 79.859544));
polyLatLng.add( new LatLng( 6.905271, 79.862609 ) );
polyLatLng.add( new LatLng( 6.906114, 79.858998 ) );
polyLatLng.add( new LatLng( 6.911808, 79.856206 ) );
polyLatLng.add( new LatLng( 6.912200, 79.851381 ) );
polyLatLng.add( new LatLng( 6.911627, 79.849621 ) );
polyLatLng.add( new LatLng( 6.910965, 79.848073 ) );
polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match first point

Log.i(TAG, "computeArea " + SphericalUtil.computeArea(polyLatLng));

map.addPolygon(new PolygonOptions()
.addAll(polyLatLng)
.strokeColor(Color.BLACK)
.strokeWidth( 4 )
.fillColor(0x220000FF));
}


Here's my geofence code which track only in circular region



 private static final float GEOFENCE_RADIUS = 1006.3975694699f; // in meters
private void startGeofence() {
Log.i(TAG, "startGeofence()");
if( geoFenceMarker != null ) {

// create geofence
Geofence geofence = createGeofence( 6.904254, 79.853798, GEOFENCE_RADIUS );
GeofencingRequest geofenceRequest = createGeofenceRequest( geofence );
addGeofence( geofenceRequest );
} else {
Log.e(TAG, "Geofence marker is null");
}
}

// Create a Geofence
private Geofence createGeofence( double lat, double lng, float radius ) {
Log.d(TAG, "createGeofence");

return new Geofence.Builder()
.setRequestId(GEOFENCE_REQ_ID)
.setCircularRegion( lat, lng, radius)
.setExpirationDuration( GEO_DURATION )
.setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER
| Geofence.GEOFENCE_TRANSITION_EXIT )
.build();
}enter code here






polygon android-maps geofencing android-geofence






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 2:06









Waleedh NaimWaleedh Naim

11




11













  • Possible duplicate of Android: Build Polygonal Shape Geofence

    – Marian Paździoch
    Nov 16 '18 at 9:13











  • I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

    – Waleedh Naim
    Nov 16 '18 at 9:22











  • "geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

    – Marian Paździoch
    Nov 16 '18 at 9:27



















  • Possible duplicate of Android: Build Polygonal Shape Geofence

    – Marian Paździoch
    Nov 16 '18 at 9:13











  • I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

    – Waleedh Naim
    Nov 16 '18 at 9:22











  • "geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

    – Marian Paździoch
    Nov 16 '18 at 9:27

















Possible duplicate of Android: Build Polygonal Shape Geofence

– Marian Paździoch
Nov 16 '18 at 9:13





Possible duplicate of Android: Build Polygonal Shape Geofence

– Marian Paździoch
Nov 16 '18 at 9:13













I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

– Waleedh Naim
Nov 16 '18 at 9:22





I tried that way too sir but i was not able to use that code inside my project. If you can help me i would really appreciate it. Thank you

– Waleedh Naim
Nov 16 '18 at 9:22













"geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

– Marian Paździoch
Nov 16 '18 at 9:27





"geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape"

– Marian Paździoch
Nov 16 '18 at 9:27












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330452%2fcreate-and-monitor-geofences-using-polygon-shape%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330452%2fcreate-and-monitor-geofences-using-polygon-shape%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python