I have the following problem with mapView in eclipse/java.
Using mapView.getOverlays() I get the error.
mapView cannot be resolved
I tried to use a local variable for mapView (using MapView) but it crashes.
Is mapView declared somewhere ?
I import com.google.android.maps.MapView;
but I can’t access the code and the offcial doc did not help
and MapView cannot be resolved or is not a field did not help too
I have installed the SDK and checked Google API in Eclipse
project build target
I can display a map without problem
and my MainActivity extends MapActivity
Here is the full code
package com.example.test_app;
import java.util.List;
import android.app.Activity;
import com.example.test_app.MyLocation;
import com.example.test_app.MyLocation.LocationResult;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.content.Context;
import android.location.Location;
import android.location.LocationProvider;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends MapActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MapView mapView = (MapView) findViewById(R.id.mapview);
if (mapView == null)
Toast.makeText(getApplicationContext(),"mapview is null",Toast.LENGTH_SHORT).show();
else
mapView.setBuiltInZoomControls(true);
setContentView(R.layout.activity_main);
LocationResult locationResult = new LocationResult(){
@Override
public void gotLocation(Location loc){
Toast.makeText(getApplicationContext()," long : " +loc.getLongitude()+ " lat :"+ loc.getLatitude(),Toast.LENGTH_SHORT).show();
//List<Overlay> mapOverlays = mapView.getOverlays();
}
};
MyLocation myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}/* End of UseGps Activity */
Add this in Your menifest
in your layout
You have a sily mistake. Move your setContentView above the declairation of the MapView. For that reason it gettting that error