android maps api v2 adding multiple circles

2019-08-22 03:10发布

I'm trying to add a circle to the map every second with an update from the gps. How would I pass the Location location = locationmanager.getLastKnownLocation(provider); to make a new circle every second? Here is what I have so far.

public class MainActivity extends Activity implements LocationListener{

Location myLocation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();


mMap.setMyLocationEnabled(true);





Location myLocation;

LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria cr = new Criteria();
String provider = locationmanager.getBestProvider(cr, true);
Location location = locationmanager.getLastKnownLocation(provider);

locationmanager.requestLocationUpdates(provider, 1000, 0, (LocationListener) this);

CircleOptions circleOptions = new CircleOptions()
.center(new LatLng( , ))
.radius(3.048); // In meters

Circle circle = mMap.addCircle(circleOptions);



 }

}

1条回答
beautiful°
2楼-- · 2019-08-22 04:05

Instead of using getLastKnownLocation, you are better of using LocationListener's callback: onLocationChange for that, which you seem to implement and request already.

To convert Location to LatLng use:

new LatLng(location.getLatitude(), location.getLongitude())
查看更多
登录 后发表回答