2013-07-20 71 views
0

我試圖用gps更新每秒添加一個圈子到地圖。我將如何通過位置location = locationmanager.getLastKnownLocation(provider);每秒創造一個新的圈子?這是我到目前爲止。android maps api v2添加多個圈子

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); 



} 

}

+0

結帳這個庫:https://github.com/i-schuetz/map_areas – Ixx

回答

1

而不是使用getLastKnownLocation的,你是用LocationListener的回調的更好:onLocationChange對於這一點,你似乎已經實現了和要求。

要轉換LocationLatLng使用:

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

這似乎與添加當前位置的新圈子,但我想它保持舊的圈子,以便我可以看到我採取了什麼路徑(類似於gps上的高亮路線)。我要添加什麼才能讓它不斷添加新的圈子?謝謝。 – johnsonjp34

+0

@ user1936916當您調用'mMap.addCircle'時會添加圓圈。只是不要調用'mMap.clear'或'circle.remove'。 –