I need to draw a path on the map. To do so, i thought about using Polyline since the new google maps. My problem is that my application works, but it doesnt draw a thing on the map. I want it to draw everytime i change position, basically to draw my path.
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) {
Lines require a minimum of two points. You are attempting to draw a line using only a single point. This will draw an infinitely small line, which you will have difficulty seeing, since it is infinitely small.
If you want to draw a line, use two or more points. If you want to draw something at a single point, use a marker, not a polyline.