android


Android check if my lat/lng position withing a given area


Suppose I have the following lat/lng that creates a polygon of area in map
39.888932, -95.557237
42.156511, -101.347921
40.322707, -101.040304
38.299884, -100.447042
36.731433, -96.623800
Now How can I check if 40.356203, -97.304952 this lat/lng is within that given area or not.
How can I do this??
Just tried Ray Casting algorithm which identifies point in polygon. This works perfect.
Refer http://en.wikipedia.org/wiki/Point_in_polygon for thesis of Ray-Casting
private boolean isPointInPolygon(LatLng tap, ArrayList<LatLng> vertices) {
int intersectCount = 0;
for (int j = 0; j < vertices.size() - 1; j++) {
if (rayCastIntersect(tap, vertices.get(j), vertices.get(j + 1))) {
intersectCount++;
}
}
return ((intersectCount % 2) == 1); // odd = inside, even = outside;
}
private boolean rayCastIntersect(LatLng tap, LatLng vertA, LatLng vertB) {
double aY = vertA.latitude;
double bY = vertB.latitude;
double aX = vertA.longitude;
double bX = vertB.longitude;
double pY = tap.latitude;
double pX = tap.longitude;
if ((aY > pY && bY > pY) || (aY < pY && bY < pY)
|| (aX < pX && bX < pX)) {
return false; // a and b can't both be above or below pt.y, and a or
// b must be east of pt.x
}
double m = (aY - bY) / (aX - bX); // Rise over run
double bee = (-aX) * m + aY; // y = mx + b
double x = (pY - bee) / m; // algebra is neat!
return x > pX;
}

Related Links

How can I apply an alpha mask to an Android drawable?
Android-load images from url into listViiew occurs every time scrolling the view
How to send a message to paired device by bluetooth
How getIntent.hasExtra method works in android
Load more data from Json in RecyclerView on Android
java.lang.IllegalStateException: Could not execute method for android:onClick
Log events Firebase Analytics for Android
edit apk decompiled code
How To Get A Part Of String?
How to prompt the user to choose default navigation application
Device specific bug with CompassOverlay?
Is it okay to use the same layout for two different activities?
Android: Variable has two states
Android TV | How to Center ListRow Items within a parent view (HorizontalGridView)
Is there any way can let greenDAO support android data-binding now?
how to get a boolean value of checkbox whether it is checked or unchecked- android studio?

Categories

HOME
beautifulsoup
hyperlink
cheerio
sitecore
spring-data-redis
knitr
edge
mips
settings
retrofit2
nstableheaderview
joomla3.0
openstreetmap
minecraft-forge
drop-down-menu
naivebayes
frequency-distribution
ag
kendo-mobile
jquery-ias
gulp-watch
aggregation
windows-server-2003
interbase
bulletphysics
paperjs
tizen-tv
google-earth
sql-server-2000
protege4
graphhopper
apns-php
linq-to-objects
chef-solo
doc
trigonometry
dcmtk
subclipse
httrack
ovf
rserve
bluez
x-ray
singleinstance
carrot2
reindex
amq
tinkerpop
oracleclient
vibrate
restore
gets
atlas
autosar
redbeard-ios
xdoclet
project-organization
user-management
vhosts
computer-architecture
lazybones
rate-limiting
intel-c++
lasso
typemock
amiga
telepat
cakephp-2.7
xmltype
procedural-programming
linkedin-jsapi
mobility
angular-carousel
codeplex
winginx
radiant
high-resolution
inputmismatchexception
windows-phone-8-sdk
octal
superscrollorama
idn
iboutlet
extconf.rb
apache-whirr
google-maps-mobile
node-redis
xcelsius
google-floodlight
zen
cfwindow
web-application-project
wcf-instancing
wysiwym
firefox-3
blind

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App