我需要在地圖上繪製路徑。爲此,我考慮了使用Polyline自新的谷歌地圖。我的問題是,我的應用程序工作,但它沒有繪製在地圖上的東西。我希望每次我改變位置時都會畫畫,基本上是爲了畫出我的路徑。無法根據當前位置在Google地圖v2上繪圖
public class MapActivity extends FragmentActivity implements LocationListener {
GoogleMap myMap;
Location lastLocation;
private LocationManager locManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean networkEnabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!networkEnabled) {
Toast.makeText(this, "network not enabled", 0);
}
}
@Override
protected void onResume() {
super.onResume();
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
lastLocation=locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Polyline line=myMap.addPolyline(new PolylineOptions().add(new LatLng(location.getLatitude(),location.getLongitude())).color(Color.RED));
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
我也面臨同樣的問題,如果你解決了這個問題,請給我一些建議。謝謝。 –