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

intent on incoming hangouts dialer number is null
How can i implement offline Wikipedia in android?
How to use tally api in android
How to let c++ program DON'T wait the adb feedback
Android Kitkat let other apps read files written to SDcard
Android Studio - Set variables by variant?
Cannot find module 'which' - Cordova android
Session Expired error in SSL HttpClient connection
How can I access .so file in apk at runtime?
Detecting front facing camera and capturing image, android?
playing HTML5 Audio on Android Chrome
Rotate + into a X and back again?
Android gradient/layer list with large center color
Having trouble getting MediaRouteActionProvider button to show up
is there a way to load a default image in picasso
Login to website without using a Webview

Categories

HOME
facebook-oauth
static
battery
hessian
saml-2.0
alarm
pdfbox
spring-data-mongodb
pyqt4
vert.x
modal-dialog
syntaxnet
appcelerator-studio
plist
stellar.js
selenium-ide
screen-readers
foreign-keys
bourbon
apache2.4
blade
href
highstock
direct3d11
ckfinder
jackson-modules
sinch
errbot
bioinformatics
dst
mustache
spring-security4
least-squares
imx6
getlasterror
raft
watchman
flatmap
node-mssql
p4merge
xv6
escpos
android-ibeacon
oracle-service-bus
bindingnavigator
tcc
xmldocument
wc
puredata
builder
launchctl
mongotemplate
boxing
filehandle
d3-force-directed
template-toolkit
google-photos
rsa-archer-grc
usart
atlas
seek
observablecollection
cfchart
stream-processing
boost-serialization
nullable
rewrite
vigenere
microsoft-reporting
video-player
lasso
cryptographichashfunction
sip-server
administration
post-commit-hook
machine-instruction
mdichild
angular-carousel
ss7
authlogic
rfc5322
breakout
modular
script#
nevron
nebula
resource-management
pdfviewer
onmousemove
lambdaj
koken
cgimage
expression-blend-4
catransform3d
google-ajax-api
quotation-marks
msr
cfwindow
skype4java
interop-domino
asynchronous-wcf-call
linfu-dynamicproxy

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