# Geofence in Ionic not working for iOS

**URL:** <https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307>\
**Category:** ionic-v3\
**Created:** [February 22, 2018, 9:34am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307 "2018-02-22T09:34:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinuvs](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@shinuvs](https://forum.ionicframework.com/u/shinuvs)\
**Post date:** [February 22, 2018, 9:34am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/1 "2018-02-22T09:34:26Z")

</div>

I used ionic geofence native plugin for Geofence and it is successfully working in Android, but it is not working for iOS. Kindly refer my below code. I can see in Xcode log geofence added successfully and monitoring location but not showing any notification.

let fence = {  
id: ‘69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb’, //any unique ID  
latitude: Number(this.cLatitude), //center of geofence radius  
longitude: Number(this.cLongitude),  
radius: this.radius, //radius to edge of geofence in meters  
transitionType: 1 , //see ‘Transition Types’ below  
notification: { //notification settings  
id: 1, //any unique ID  
title: ‘You have crossed a fence.’, //notification title  
text: ‘You just left the site.’, //notification body  
openAppOnClick: true //open app when notification is tapped  
}  
}

```
  this.geofence.addOrUpdate(fence).then(
    () => console.log('Geofence added ios and android'),
    (err) => console.log('Geofence failed to add')
  );

  this.geofence.onTransitionReceived().subscribe(resp => {
    console.log("resp :", resp);
    //alert("You just crossed the fence");
  });
```

---

<div class="post-metadata">

**Author:** ![devsm](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@devsm](https://forum.ionicframework.com/u/devsm)\
**Post date:** [May 15, 2018, 8:02am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/2 "2018-05-15T08:02:07Z")

</div>

Have you found a solution?? I’m stuck with the same problem…

---

<div class="post-metadata">

**Author:** ![jorgster](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jorgster](https://forum.ionicframework.com/u/jorgster)\
**Post date:** [May 15, 2018, 8:14am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/3 "2018-05-15T08:14:06Z")

</div>

Think the Ionic team could start prioritizing helping the community a little bit more… It’s frustrating how absent they are.

---

<div class="post-metadata">

**Author:** ![shinuvs](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@shinuvs](https://forum.ionicframework.com/u/shinuvs)\
**Post date:** [June 1, 2018, 6:15am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/4 "2018-06-01T06:15:40Z")

</div>

I have removed that and create fence using geolocation

---

<div class="post-metadata">

**Author:** ![jorgster](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jorgster](https://forum.ionicframework.com/u/jorgster)\
**Post date:** [June 1, 2018, 9:19am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/5 "2018-06-01T09:19:09Z")

</div>

Would ut be possible for you to svare the code? Ut would be to so much help.

---

<div class="post-metadata">

**Author:** ![shinuvs](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@shinuvs](https://forum.ionicframework.com/u/shinuvs)\
**Post date:** [June 12, 2018, 6:32am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/6 "2018-06-12T06:32:42Z")

</div>

I just used the this link for location update

> **[Adding Background Geolocation to an Ionic 2 & 3 Application](https://www.joshmorony.com/adding-background-geolocation-to-an-ionic-2-application/)**
>
> In a previous tutorial, I have demonstrated how to use Geolocation in an Ionic 2 application. The method used in that tutorial is the “standard” way to use the Geolocation plugin, it wi…

Also for fence please use this method.

getDistanceFromLatLonInm(lat1,lon1,lat2,lon2) {  
var R = 6371; // Radius of the earth in km  
var dLat = this.deg2rad(lat2-lat1); // deg2rad below  
var dLon = this.deg2rad(lon2-lon1);  
var a =  
Math.sin(dLat/2) \* Math.sin(dLat/2) +  
Math.cos(this.deg2rad(lat1)) \* Math.cos(this.deg2rad(lat2)) \*  
Math.sin(dLon/2) \* Math.sin(dLon/2)  
;  
var c = 2 \* Math.atan2(Math.sqrt(a), Math.sqrt(1-a));  
var d = R \* c; // Distance in km  
var m = d\*1000;  
return m;  
}

deg2rad(deg) {  
return deg \* (Math.PI/180)  
}

---

<div class="post-metadata">

**Author:** ![jorgster](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jorgster](https://forum.ionicframework.com/u/jorgster)\
**Post date:** [June 25, 2018, 10:09am UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/7 "2018-06-25T10:09:28Z")

</div>

> [@shinuvs](#):
>
> .PI/

This doesnt really tell me much about the geofence… This just calculates the distance, right?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:49pm UTC](https://forum.ionicframework.com/t/geofence-in-ionic-not-working-for-ios/122307/8 "2021-07-19T21:49:50Z")

</div>


