我需要在地图上画一条路径。为此,我从新的谷歌地图开始考虑使用折线。我的问题是我的应用程序可以工作,但它没有在地图上绘制任何东西。我希望它在每次我改变位置时绘制,基本上是为了绘制我的路径。
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) {