android - LatLngBounds.contains returns true even if LatLng is not within the defined boundary -


i'm stumped; ff. method intend return true if latlng within latlngbounds or return true if latlng part of boundary set including?

https://developers.google.com/android/reference/com/google/android/gms/maps/model/latlngbounds#contains(com.google.android.gms.maps.model.latlng)

so far tests counterproductive; returns true if latlng outside latlngbounds.

latlngbounds latlngbounds = // boundaries of location latlng target = cameraposition.target; // returns center of camera if (!latlngbounds.contains(target)) {     // processes } 

what display toast message if camera panned outside polygon (i log it) apparently, have scroll way away polygon show.

i use polygon.getpoints latlngbounds

it should return false if it's outside polygon (latlngbounds defined)

i did simple test, , contains() method return true point within bounds, , return false considers points outside of bounds.

i used extreme example, bounds set country of australia, , tested point inside australia, , point in san francisco.

the bounds:

private latlngbounds australia = new latlngbounds(         new latlng(-44, 113), new latlng(-10, 154)); 

first test, point within australia:

           if (australia.contains(new latlng(-31.693598,147.843026))){                  toast.maketext(mapsactivity.this, "inside bounds", toast.length_long).show();             }             else{                 toast.maketext(mapsactivity.this, "outside bounds", toast.length_long).show();             } 

result:

inaustralia

then, tested point in san francisco:

            if (australia.contains(new latlng(37.7942635,-122.3955861))){                 toast.maketext(mapsactivity.this, "inside bounds", toast.length_long).show();             }             else{                 toast.maketext(mapsactivity.this, "outside bounds", toast.length_long).show();             } 

result:

insanfrancisco

so, looks it's working expected given clear cut example.

the question how far outside of bounds need in order contains() method return false.

for test didn't make calls including(), presumably contains() method return true based on description in documentation:

creates new bounds based on southwest , northeast corner.

the bounds conceptually includes points where:

the latitude in range [northeast.latitude, southwest.latitude]; longitude in range [southwest.longtitude, northeast.longitude] if southwest.longtitude ≤ northeast.longitude; , longitude in range [southwest.longitude, 180) ∪ [-180, northeast.longitude] if southwest.longtitude > northeast.longitude.

if bounds modified calls including(), documentation states bounds modified so:

returns new latlngbounds extends latlngbounds include given latlng. return smallest latlngbounds contains both , point.

in particular, consider extending bounds both in eastward , westward directions (one of may cross antimeridian) , choose smaller of two. in case both directions result in latlngbounds of same size, extend in eastward direction.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -