surialabs / react-native-geo-fencing

Native modules to determine if a location is within defined geographical boundaries using Google Geometry library
139 stars 33 forks source link

Android issue with React Native 0.53 #8

Open imjaadH opened 6 years ago

imjaadH commented 6 years ago

On ios everything works fine but i got an error on android app. This is more like a tip for those who are starting out with newer react native version. If you get this error com.google.android.gms.maps.model null Just add this inside your build.gradle file and recompile compile "com.google.android.gms:play-services-maps:11.6.0"

ydv0121 commented 6 years ago

in ios not working for me...please help

const polygon = [ {"lat": 37.42380853737998,"lng": -122.08662271499634}, {"lat": 37.42352949259187,"lng": -122.08644200116395}, {"lat": 37.42384474922283,"lng": -122.08275865763426}, {"lat": 37.42008900856639,"lng": -122.08249680697918}, {"lat": 37.42134369453038,"lng": -122.08579190075396}, // last point has to be same as first point ];

let point = {
  "lat": 37.421998333333335,
  "lng": -122.08400000000002
};

GeoFencing.containsLocation(point, polygon)
  .then(() => console.log('point is within polygon'))
  .catch(() => console.log('point is NOT within polygon'))

my coordinates is inside of polygon always describe "point is not within polygon" in IOS only

in android its working fine. also with realtime coordinates

imjaadH commented 6 years ago

Hi sorry for the late reply thats strange, i was using ios simulator and with custom location it was working fine afaik, are you testing on a device or simulator

ydv0121 commented 6 years ago

yes i am testing on simulator. and custom location not working..

**see this is my custom location. const polygon = [ {"lat": 37.42380853737998,"lng": -122.08662271499634}, {"lat": 37.42352949259187,"lng": -122.08644200116395}, {"lat": 37.42384474922283,"lng": -122.08275865763426}, {"lat": 37.42008900856639,"lng": -122.08249680697918}, {"lat": 37.42134369453038,"lng": -122.08579190075396}, // last point has to be same as first point ];

let point = { "lat": 37.421998333333335, "lng": -122.08400000000002 };

GeoFencing.containsLocation(point, polygon) .then(() => console.log('point is within polygon')) .catch(() => console.log('point is NOT within polygon'))**

it always display POINT IS NOT WITHIN POLYGON

is there any particular installation procedure for ios ?

imjaadH commented 6 years ago

Not particular, you have to just link the libraries and install in podfile thats it. If its not propperly installed it would have given error already. So i guess something is really wrong with library. I spend half of the day on android real device..zero success untill i kinda realized this thing is not useful for physical devices & ended up doing something else :(

ydv0121 commented 6 years ago

in android for me its working with live location.. can you send me your ios codes if possible?

imjaadH commented 6 years ago

Try on ios simulator one more time, if it works then we can conclude that it works on simulators and not real devices, let me know i ll share the code although its just like the one in docs nothing fancy...

hasan642 commented 5 years ago

@ydv0121 can you help me plz !!!

ydv0121 commented 5 years ago

@hasanal1995 about what?

hasan642 commented 5 years ago

it is not working only if lat and lng fully matching, can i set radius ?

ydv0121 commented 5 years ago

i don't know about it when lat lng fully matching

hasan642 commented 5 years ago

i mean it is not working only if point equals one of geofences. example: import React from 'react'; import GeoFencing from 'react-native-geo-fencing'; //__ export default class extends React.Component { componentDidMount() { const polygon = [ { lat: 32.0176763, lng: 36.0081422 }, ];

    navigator.geolocation.getCurrentPosition(
        (position) => {
            console.log('positio is', position)
            let point = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };

            GeoFencing.containsLocation(point, polygon)
                .then(() => console.log('point is within polygon'))
                .catch(() => console.log('point is NOT within polygon'))
        },
        (error) => alert(error.message),
        { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 }
    );
}

render() { return null; }

}

// if point equal { lat: 32.0176763, lng: 36.0081422 } "point is within polygon", else if is not equal exactly "point is NOT within polygon".

are you understand me bro ?

ydv0121 commented 5 years ago

yes understood but looks like you are matching with only one lat-lng with your current location...in polygon/radius there are starting and ending points ..

your polygon must have starting and ending points like this

screenshot_1542946700 png

const polygon = [ {"lat": 37.42380853737998,"lng": -122.08662271499634}, {"lat": 37.42352949259187,"lng": -122.08644200116395}, {"lat": 37.42384474922283,"lng": -122.08275865763426}, {"lat": 37.42008900856639,"lng": -122.08249680697918}, {"lat": 37.42134369453038,"lng": -122.08579190075396}, // last point has to be same as first point ];

hasan642 commented 5 years ago

You mean first coordinates must be as last coordinates? And coordinates between them can be different ??

JefriBulo commented 5 years ago

Hello Friend I want to ask something about this geofencing

My lat long coordinates is inside the "const polygon" but still show "point is NOT within polygon" or "you are outside of polygon". I'm using my android real device for this project. Can you help me about this problem? thanks in advance

JefriBulo commented 5 years ago

I'm currently using react-native-cli: 2.0.1 and react-native: 0.57.1 version. Any solutions? Thanks friends