4

when i extends the MapActivity class it shows an error.

error is: cant resolved datatype. why?

how to add a maps.jar in my project?

thanks.

3 Answers 3

9

You probably haven't done the steps required to set up a Maps project as described in Maps External API Overview. There is no maps.jar to add. Read the document I linked to, and you should be all set.

0

Google Map View : Creating a Map Activity

-1

Here is my code :

    import java.io.IOException;
    import java.util.List;
    import java.util.Locale;

    import android.content.Context;
    import android.graphics.Canvas;
    import android.location.Address;
    import android.location.Geocoder;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.widget.Toast;

    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapController;
    import com.google.android.maps.MapView;
    import com.google.android.maps.Overlay;

    public class MyMapsActivity extends MapActivity 
    {    

            MapView mapView;
        MapController mapController;
        LocationManager locationManager;
        LocationListener locationListener;
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
                 {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.main);

                    mapView = (MapView) findViewById(R.id.mapView);
                    // enable Street view by default
                    mapView.setStreetView(true);

                    // enable to show Satellite view
                   // mapView.setSatellite(true);

                  // enable to show Traffic on map
                   // mapView.setTraffic(true);

                    mapView.setBuiltInZoomControls(true);

                    mapController = mapView.getController();
                    mapController.setZoom(5); 


       locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  

       locationListener = new GPSLocationListener();

       locationManager.requestLocationUpdates(
      LocationManager.GPS_PROVIDER, 
      0, 
      0, 
      locationListener);

    Touchy t = new Touchy();
    List<Overlay> overlayList = mapView.getOverlays();
    overlayList.add(t);

}
@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}


class Touchy extends Overlay
{
 public boolean onTap(GeoPoint point, MapView mapView) 
     {
       Context contexto = mapView.getContext();
       String msg = "Latitude : " + point.getLatitudeE6()/1E6 + " - " + 
                    "Longitude : " + point.getLongitudeE6()/1E6;

      Toast toast = Toast.makeText(contexto, msg, Toast.LENGTH_SHORT);
     toast.show();

      return true;
     }
  }


   private class GPSLocationListener implements LocationListener 
   {
    public void onLocationChanged(Location location)
    {
    if (location != null)
    {
      GeoPoint point = new GeoPoint(
          (int) (location.getLatitude() * 1E6), 
          (int) (location.getLongitude() * 1E6));

      Toast.makeText(getBaseContext(), 
          "Latitude: " + location.getLatitude() + 
          " Longitude: " + location.getLongitude(), 
          Toast.LENGTH_SHORT).show();

      mapController.animateTo(point);
      mapController.setZoom(5);
      mapView.invalidate();
    }

      if (location != null)
      {
          GeoPoint point=null;
          String address = ConvertPointToLocation(point);
          Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

       }


    }

  public String ConvertPointToLocation(GeoPoint point) {   
        String address = "";
        Geocoder geoCoder = new Geocoder(
            getBaseContext(), Locale.getDefault());
        try {
          List<Address> addresses = geoCoder.getFromLocation(
            point.getLatitudeE6()  / 1E6, 
            point.getLongitudeE6() / 1E6, 1);

          if (addresses.size() > 0) {
            for (int index = 0; 
        index < addresses.get(0).getMaxAddressLineIndex(); index++)
              address += addresses.get(0).getAddressLine(index) + " ";
          }
        }
        catch (IOException e) {        
          e.printStackTrace();
        }   

        return address;
      }

public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

} 
  }

public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}
}

Layout Coding :

   <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout 
           xmlns:android="http://schemas.android.com/apk/res/android" 
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent">

   <com.google.android.maps.MapView 
               android:id="@+id/mapView"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:enabled="true"
               android:clickable="true"
               android:apiKey="Your MAP API Key"

    />

   <LinearLayout android:id="@+id/zoom" 
                 android:layout_width="wrap_content" 
                 android:layout_height="wrap_content" 
                 android:layout_alignParentBottom="true" 
                 android:layout_centerHorizontal="true" 
    />

    </RelativeLayout>

Link for getting own API key process :

http://sanathnandasiri.blogspot.in/2011/04/obtaining-google-maps-api-key-for.html

4
  • How does this relate to the question at all besides usage of the MapActivity class?
    – BoltClock
    Sep 26, 2012 at 10:26
  • @Praveen want to create map activity and I provide full source code. Now just ignore all errors. Sep 26, 2012 at 11:13
  • 1
    You're not supposed to provide full source code in an answer. That doesn't answer the question.
    – BoltClock
    Sep 26, 2012 at 11:15
  • What about @Jorgesys answer? He provide link that contain also some piece of code to create a map activity. And Praveen didn't give description about his source code. That's why I provide full source code. I don't think I were wrong and someone downvote my answer. Sep 26, 2012 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.