简体   繁体   中英

Geofencing in Android

I am getting a kmz-file from a webservice, which I use for geofencing. The app is responsible to check whether the gps-location of the phone is within the geofence, or not.

I don't really know how the kmz-file will be structured (I am not creating it), but I think the coordinates might look like this:

<coordinates> 
    -112.2550785337791,36.07954952145647,2357
    -112.2549277039738,36.08117083492122,2357
    -112.2552505069063,36.08260761307279,2357
    -112.2564540158376,36.08395660588506,2357
    -112.2644963846444,36.08627897945274,2357
    -112.2656969554589,36.08649599090644,2357 
</coordinates>

How can I check if the gps-coordinates of my phone are within the geofence (the example above is only a line, it should be a closed area, for example a rectangle)? Right now I can't really think of how to do that.

And what library should be used to access the kmz-files?

First, for geofencing, download the sample from here and read the documentation. And I don;t know about kmz file. But if you can get the string from it(using file reading) and know its structure, then you can easily parse it. If the format is like you mentioned, then you can get the values by following method:

  • Split the string on coordinates (including <>). You will get a string array. Take the string at index 1.

  • Split this string on /coordinates (including <>). You will get another string array. Take the string at index 0.

  • Now split this string on ",". You will get an array of strings again! Now at indexes 0,3,6... are latitudes and at indexes 1,4,7... are longitudes and at indexes 2,5,8... are the third number in the data you mentioned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM