Skip to content Skip to sidebar Skip to footer

Mapactivity Class In Android?

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.

Solution 1:

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.

Solution 2:

Google Map View : Creating a Map Activity

Solution 3:

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;

    publicclassMyMapsActivityextendsMapActivity 
    {    

            MapView mapView;
        MapController mapController;
        LocationManager locationManager;
        LocationListener locationListener;
            /** Called when the activity is first created. */@OverridepublicvoidonCreate(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 = newGPSLocationListener();

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

    Touchyt=newTouchy();
    List<Overlay> overlayList = mapView.getOverlays();
    overlayList.add(t);

}
@OverrideprotectedbooleanisRouteDisplayed() {
    // TODO Auto-generated method stubreturnfalse;
}


classTouchyextendsOverlay
{
 publicbooleanonTap(GeoPoint point, MapView mapView) 
     {
       Contextcontexto= mapView.getContext();
       Stringmsg="Latitude : " + point.getLatitudeE6()/1E6 + " - " + 
                    "Longitude : " + point.getLongitudeE6()/1E6;

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

      returntrue;
     }
  }


   privateclassGPSLocationListenerimplementsLocationListener 
   {
    publicvoidonLocationChanged(Location location)
    {
    if (location != null)
    {
      GeoPointpoint=newGeoPoint(
          (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;
          Stringaddress= ConvertPointToLocation(point);
          Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

       }


    }

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

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

        return address;
      }

publicvoidonProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

publicvoidonProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

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

} 
  }

publicvoidonProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

publicvoidonProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

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

}
}

Layout Coding :

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"><com.google.android.maps.MapViewandroid: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"

    /><LinearLayoutandroid: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

Post a Comment for "Mapactivity Class In Android?"