timurinamanu
Lurker
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
GPSTracker.java
Android Manifest.xml
layout/main.xml
note: the api Key is little changed.
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:
package gps.tracker;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
mContext = context;
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
Code:
package gps.tracker;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class GPSTracker extends MapActivity implements LocationListener {
private LocationManager lm;
TextView tv;
HelloItemizedOverlay itemizedoverlay;
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1l,1l, this);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
itemizedoverlay = new HelloItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
public void onLocationChanged(Location arg0) {
double lat = arg0.getLatitude();
double lon = arg0.getLongitude();
//Log.e("GPS", "location changed: lat="+lat+", lon="+lon);
//TextView tv = new TextView(this);
//tv.setText(tv.getText()+"\nlocation changed: lat="+lat+", lon="+lon);
//setContentView(tv);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
itemizedoverlay = new HelloItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem = new OverlayItem(new GeoPoint((int)lat,(int)lon),"es funkt","juhu");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
public void onProviderDisabled(String arg0) {
Log.e("GPS", "provider disabled " + arg0);
//tv = new TextView(this);
//tv.setText(tv.getText()+"\nprovider disabled " + arg0);
//setContentView(tv);
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
//Log.e("GPS", "status changed to " + arg0 + " [" + arg1 + "]");
//tv = new TextView(this);
//tv.setText(tv.getText()+"\nstatus changed to " + arg0 + " [" + arg1 + "]");
//setContentView(tv);
//OverlayItem overlayitem = new OverlayItem(new Point(arg0.get), "Hola, Mundo!", "I'm in Mexico City!");
}
public void onProviderEnabled(String arg0) {
Log.e("GPS", "provider enabled " + arg0);
//tv = new TextView(this);
tv.setText(tv.getText()+"\nprovider enabled " + arg0);
//setContentView(tv);
}
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Android Manifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gps.tracker"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GPSTracker"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
</manifest>
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<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"/>
</LinearLayout>