本文介绍了android maps api v2添加多个圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过gps的更新每秒向地图添加一个圆圈.我将如何传递Location location = locationmanager.getLastKnownLocation(provider);每秒钟做一个新的圈子?这是我到目前为止所拥有的.
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);
}
}
推荐答案
最好使用LocationListener
的回调:onLocationChange
,而不是使用getLastKnownLocation
,您似乎已经实现并请求了
Instead of using getLastKnownLocation
, you are better of using LocationListener
's callback: onLocationChange
for that, which you seem to implement and request already.
要将Location
转换为LatLng
,请使用:
new LatLng(location.getLatitude(), location.getLongitude())
这篇关于android maps api v2添加多个圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!