Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if user is inside a Circle Google maps v2
    primarykey
    data
    text
    <p>I have a circle on my map. Now I want to detect if the user (or me) is inside the circle.</p> <pre><code> Circle circle = map.addCircle(new CircleOptions() .center(new LatLng(14.635594, 121.032962)) .radius(55) .strokeColor(Color.RED) ); </code></pre> <p>I have this code:</p> <pre><code> LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationListener ll = new myLocationListener(); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,ll); Location.distanceBetween( pLat,pLong, circle.getCenter().latitude, circle.getCenter().longitude, distance); if( distance[0] &gt; circle.getRadius() ){ Toast.makeText(getBaseContext(), "Outside", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getBaseContext(), "Inside", Toast.LENGTH_LONG).show(); } </code></pre> <p>And on myLocationListener I have this:</p> <pre><code>public void onLocationChanged(Location location) { // TODO Auto-generated method stub pLong = location.getLongitude(); pLat = location.getLatitude(); } </code></pre> <p>It works correctly if I parameter inside <code>distanceBetween</code> is the coordinates of marker, however, the toast displays <strong>Outside</strong> even though my location is inside the radius.</p> <p><img src="https://i.stack.imgur.com/0TGQL.png" alt="enter image description here"></p> <p>Any ideas how to do this correctly? Please help. Thanks!</p> <p><strong>EDIT</strong></p> <p>I discovered something odd.</p> <p>On the picture, you can see I have a textView above which has 5 numbers (circle Latitude, circle longitude, distance at index 0 , distance at index 1 , distance<a href="https://i.stack.imgur.com/QUwoB.png" rel="noreferrer">2</a>). <code>distance</code> is a float array to store the distance between the center of the circle and the user location. I set the radius to 100, and I think the unit is meters, however, as you can see, the values at the <code>distance</code> array are : <strong>1.334880E7</strong> , <strong>-81.25308990478516</strong> , <strong>-10696092987060547</strong> . What is the formula for the computation of the distance? And also, 1.something times 10 raise to 7 is about 13 million which is really greater than 100. Please help its really confusing right now. According to documentation of Circle (The radius of the circle, specified in meters. It should be zero or greater.) and distanceBetween (Computes the approximate distance in meters between two locations) so I don't know why is this the result.</p> <p><img src="https://i.stack.imgur.com/QUwoB.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload