android maps api v2添加多个圆圈

时间:2013-07-20 20:46:31

标签: google-maps google-maps-android-api-2 android-maps-v2

我正试图通过gps的更新每秒向地图添加一个圆圈。我如何传递Location location = locationmanager.getLastKnownLocation(provider);每秒钟创造一个新的圈子?这是我到目前为止所拥有的。

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 个答案:

答案 0 :(得分:2)

而不是使用getLastKnownLocation,您最好使用LocationListener的回调:onLocationChange,而您似乎已经实现并请求了。{/ p>

要将Location转换为LatLng,请使用:

new LatLng(location.getLatitude(), location.getLongitude())