1. Check out our companion app, Forums for Android! Download from Google Play

Google Maps, GSP, Application stops unexpectedly

Discussion in 'Application Development' started by timurinamanu, Oct 15, 2010.

  1. timurinamanu

    timurinamanu New Member
    Thread Starter
    5

    Oct 15, 2010
    2
    0
    5
    Hallo!
    I am a student and i wrote a program that reads ands shows the gps position at google maps.

    Yesterday it was working, then changed the code a little and then the problems began. I always get the error:The application GPS(process gps.tracker) has stopped unexpectedly. Please try again.

    I tried to debug but the application crashes before even coming to the activity ....
    pls someone help

    My Code:
    HalloItemizedOverlay.java
    Code (Text):
    1.  
    2. package gps.tracker;
    3.  
    4. import java.util.ArrayList;
    5.  
    6. import android.app.AlertDialog;
    7. import android.content.Context;
    8. import android.graphics.drawable.Drawable;
    9.  
    10. import com.google.android.maps.ItemizedOverlay;
    11. import com.google.android.maps.OverlayItem;
    12.  
    13. public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    14.     private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    15.     Context mContext;
    16.     public HelloItemizedOverlay(Drawable defaultMarker) {
    17.           super(boundCenterBottom(defaultMarker));
    18.         }
    19.     public void addOverlay(OverlayItem overlay) {
    20.         mOverlays.add(overlay);
    21.         populate();
    22.     }
    23.     @Override
    24.     protected OverlayItem createItem(int i) {
    25.       return mOverlays.get(i);
    26.     }
    27.     @Override
    28.     public int size() {
    29.       return mOverlays.size();
    30.     }
    31.     public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    32.           super(defaultMarker);
    33.           mContext = context;
    34.     }
    35.     @Override
    36.     protected boolean onTap(int index) {
    37.       OverlayItem item = mOverlays.get(index);
    38.       AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    39.       dialog.setTitle(item.getTitle());
    40.       dialog.setMessage(item.getSnippet());
    41.       dialog.show();
    42.       return true;
    43.     }
    44. }
    45.  
    46.  
    GPSTracker.java
    Code (Text):
    1.  
    2. package gps.tracker;
    3.  
    4.  
    5. import java.util.List;
    6. import com.google.android.maps.GeoPoint;
    7. import com.google.android.maps.MapActivity;
    8. import com.google.android.maps.MapView;
    9. import com.google.android.maps.Overlay;
    10. import com.google.android.maps.OverlayItem;
    11. import android.content.Context;
    12. import android.graphics.drawable.Drawable;
    13. import android.location.Location;
    14. import android.location.LocationListener;
    15. import android.location.LocationManager;
    16. import android.os.Bundle;
    17. import android.util.Log;
    18. import android.widget.TextView;
    19.  
    20. public class GPSTracker extends MapActivity implements LocationListener {
    21.          private LocationManager lm;
    22.         TextView tv;
    23.         HelloItemizedOverlay itemizedoverlay;
    24.         private MapView mapView;
    25.     @Override
    26.     public void onCreate(Bundle savedInstanceState) {
    27.         super.onCreate(savedInstanceState);
    28.         setContentView(R.layout.main);
    29.         lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    30.         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1l,1l, this);
    31.         mapView = (MapView) findViewById(R.id.mapview);
    32.         mapView.setBuiltInZoomControls(true);
    33.         List<Overlay> mapOverlays = mapView.getOverlays();
    34.         Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
    35.         itemizedoverlay = new HelloItemizedOverlay(drawable);
    36.  
    37.         GeoPoint point = new GeoPoint(35410000, 139460000);
    38.         OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    39.         itemizedoverlay.addOverlay(overlayitem);
    40.         mapOverlays.add(itemizedoverlay);
    41.        
    42.     }
    43.     public void onLocationChanged(Location arg0) {
    44.         double lat = arg0.getLatitude();
    45.         double lon = arg0.getLongitude();
    46.         //Log.e("GPS", "location changed: lat="+lat+", lon="+lon);
    47.         //TextView tv = new TextView(this);
    48.         //tv.setText(tv.getText()+"\nlocation changed: lat="+lat+", lon="+lon);
    49.         //setContentView(tv);
    50.         mapView = (MapView) findViewById(R.id.mapview);
    51.        
    52.         mapView.setBuiltInZoomControls(true);
    53.         List<Overlay> mapOverlays = mapView.getOverlays();
    54.         Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
    55.         itemizedoverlay = new HelloItemizedOverlay(drawable);
    56.  
    57.         GeoPoint point = new GeoPoint(35410000, 139460000);
    58.         OverlayItem overlayitem = new OverlayItem(new GeoPoint((int)lat,(int)lon),"es funkt","juhu");
    59.         itemizedoverlay.addOverlay(overlayitem);
    60.         mapOverlays.add(itemizedoverlay);
    61.     }
    62.     public void onProviderDisabled(String arg0) {
    63.             Log.e("GPS", "provider disabled " + arg0);
    64.             //tv = new TextView(this);
    65.             //tv.setText(tv.getText()+"\nprovider disabled " + arg0);
    66.             //setContentView(tv);
    67.     }
    68.     public void  onStatusChanged(String arg0, int arg1, Bundle arg2) {
    69.         //Log.e("GPS", "status changed to " + arg0 + " [" + arg1 + "]");
    70.         //tv = new TextView(this);
    71.         //tv.setText(tv.getText()+"\nstatus changed to " + arg0 + " [" + arg1 + "]");
    72.         //setContentView(tv);
    73.         //OverlayItem overlayitem = new OverlayItem(new Point(arg0.get), "Hola, Mundo!", "I'm in Mexico City!");
    74.     }
    75.     public void onProviderEnabled(String arg0) {
    76.             Log.e("GPS", "provider enabled " + arg0);
    77.             //tv = new TextView(this);
    78.             tv.setText(tv.getText()+"\nprovider enabled " + arg0);
    79.             //setContentView(tv);
    80.     }
    81.     protected boolean isRouteDisplayed() {
    82.         // TODO Auto-generated method stub
    83.         return false;
    84.     }
    85. }
    86.  
    Android Manifest.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.       package="gps.tracker"
    5.       android:versionCode="1"
    6.       android:versionName="1.0">
    7.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    8.         <activity android:name=".GPSTracker"
    9.                   android:label="@string/app_name">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.         </activity>
    15.     </application>
    16.     <uses-sdk android:minSdkVersion="7" />
    17.     <uses-permission android:name="android.permission.INTERNET" />
    18. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    19. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
    20. </uses-permission>
    21. <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS">
    22. </uses-permission>
    23. <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
    24. </uses-permission>
    25. <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES">
    26. </uses-permission>
    27. <uses-permission android:name="android.permission.INTERNET">
    28. </uses-permission>
    29. </manifest>
    30.  
    layout/main.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="vertical"
    5.     android:layout_width="fill_parent"
    6.     android:layout_height="fill_parent"
    7.     >
    8. <TextView  
    9.     android:layout_width="fill_parent"
    10.     android:layout_height="wrap_content"
    11.     android:text="@string/hello"
    12.     />
    13. <com.google.android.maps.MapView     xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/mapview"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:clickable="true"    android:apiKey="XXX0mOKTuceGn88c3erWXXXXXXXXXX"/>
    14. </LinearLayout>
    15.  
    note: the api Key is little changed.
     

    Advertisement

  2. timurinamanu

    timurinamanu New Member
    Thread Starter
    5

    Oct 15, 2010
    2
    0
    5
    Problem solved!!!

    had to add
    </activity>
    <uses-library android:name="com.google.android.maps" />
    after </activity>
     

Share This Page

Loading...