LatLng Points on circle on Google Map V2 in Android

后端 未结 1 1244
广开言路
广开言路 2021-01-13 09:01

I need to store all the LatLng points of circle drawn on google map. like : \"enter

I

相关标签:
1条回答
  • 2021-01-13 09:20

    The 'zoom' factor is not relevant for the calculations here. Update your makeCircle() method as shown below and it will work exactly the way you want:

    private ArrayList<LatLng> makeCircle(LatLng centre, double radius) 
        { 
        ArrayList<LatLng> points = new ArrayList<LatLng>(); 
    
        double EARTH_RADIUS = 6378100.0; 
        // Convert to radians. 
        double lat = centre.latitude * Math.PI / 180.0; 
        double lon = centre.longitude * Math.PI / 180.0; 
    
        for (double t = 0; t <= Math.PI * 2; t += 0.3) 
        { 
        // y 
        double latPoint = lat + (radius / EARTH_RADIUS) * Math.sin(t); 
        // x 
        double lonPoint = lon + (radius / EARTH_RADIUS) * Math.cos(t) / Math.cos(lat);
    
        // saving the location on circle as a LatLng point
        LatLng point =new LatLng(latPoint * 180.0 / Math.PI, lonPoint * 180.0 / Math.PI);
    
        // here mMap is my GoogleMap object 
        mMap.addMarker(new MarkerOptions().position(point));
    
        // now here note that same point(lat/lng) is used for marker as well as saved in the ArrayList 
        points.add(point);
    
        } 
    
        return points; 
        }
    

    I am sure it helped you :)

    0 讨论(0)
提交回复
热议问题