Reputation: 43
Hi Im playing around with an android map app tutorial, but I'm getting lots of errors because I dont seem to be importing the com.google.andoid.maps package properly because eclipse is giving me an error for the import and any of its classes. Is there any reason why it shouldnt be working.
import com.google.android.maps.*;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ShowTheMap extends MapActivity {
private static double lat;
private static double lon;
private int latE6;
private int lonE6;
private MapController mapControl;
private GeoPoint gp;
private MapView mapView;
private Button overlayButton, accessButton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // Suppress title bar for more space
setContentView(R.layout.showthemap);
// Add map controller with zoom controls
mapView = (MapView) findViewById(R.id.mv);
mapView.setSatellite(false);
mapView.setTraffic(false);
mapView.setBuiltInZoomControls(true); // Set android:clickable=true in main.xml
int maxZoom = mapView.getMaxZoomLevel();
int initZoom = maxZoom-2;
mapControl = mapView.getController();
mapControl.setZoom(initZoom);
// Convert lat/long in degrees into integers in microdegrees
latE6 = (int) (lat*1e6);
lonE6 = (int) (lon*1e6);
gp = new GeoPoint(latE6, lonE6);
mapControl.animateTo(gp);
// Button to control food overlay
overlayButton = (Button)findViewById(R.id.doOverlay);
overlayButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
}
});
// Button to control access overlay
accessButton = (Button)findViewById(R.id.doAccess);
accessButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
}
});
}
// Method to insert latitude and longitude in degrees
public static void putLatLong(double latitude, double longitude){
lat = latitude;
lon =longitude;
}
// This sets the s key on the phone to toggle between satellite and map view
// and the t key to toggle between traffic and no traffic view (traffic view
// relevant only in urban areas where it is reported).
public boolean onKeyDown(int keyCode, KeyEvent e){
if(keyCode == KeyEvent.KEYCODE_S){
mapView.setSatellite(!mapView.isSatellite());
return true;
} else if(keyCode == KeyEvent.KEYCODE_T){
mapView.setTraffic(!mapView.isTraffic());
mapControl.animateTo(gp); // To ensure change displays immediately
}
return(super.onKeyDown(keyCode, e));
}
// Required method since class extends MapActivity
@Override
protected boolean isRouteDisplayed() {
return false; // Don't display a route
}
}
Upvotes: 1
Views: 2497
Reputation: 16255
This sounds like it may just be that you are missing the needed packages. Make sure you download the Google APIs in Eclipse with the SDK Manager.
Take a look at this page for some details. https://developers.google.com/android/add-ons/google-apis/installing
A quick snippet from that page mentions this sort of issue
Select the Google APIs Add-On that you want to install and click Install Selected. The add-on is downloaded to your computer and installed in your SDK environment.
When you are ready to develop against the add-on. set your application's properties so that it uses the Google APIs Add-On as the build target. To run the application, create an Android Virtual Device that uses the add-on as it's target. Make sure to select the version (by API level) that is appropriate for your app.
To give your applications access to the Maps library included in the add-on, you need to configure your development and run-time environments properly. The process for doing that is described in the Maps Overview document, which you should read next.
For example
After that you to reference those new packages so you need to change your Project Build Target
For example
Upvotes: 0
Reputation: 6771
You should be basing your project not off "Android 4.2" but instead off "Google API" with Platform 4.2.
This can be changed in your project properties - Android - Project Build Target.
Upvotes: 1