where am i application stops unexpectedly

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

where am i application stops unexpectedly

Postby schofeild » Fri Jul 23, 2010 6:02 pm

on running d application on emulator i get d following error:application com.paad.whereami has stopped unexpectedly
i have used all d necessary permissions like internet , fine location as well as com.google.android.maps library....i also have used a valid map key.........
i am currently using sdk 2.2 and google api 8..........
this program was originally written for google api 7....so do i need to install google api 7.........

plzz guys help me out ......any help would be really appreciated....... :D


the source code is as follows:
(where am i.java class)
package com.paad.whereami;

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

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;

import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class WhereAmI extends MapActivity {
@Override
protected boolean isRouteDisplayed() {
return false;
}

MapController mapController;
MyPositionOverlay positionOverlay;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MapView myMapView = (MapView)findViewById(R.id.myMapView);
mapController = myMapView.getController();

myMapView.setSatellite(true);
myMapView.setStreetView(true);
myMapView.displayZoomControls(false);

mapController.setZoom(17);

// Add the MyPositionOverlay
positionOverlay = new MyPositionOverlay();
List<Overlay> overlays = myMapView.getOverlays();
overlays.add(positionOverlay);

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

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);

updateWithNewLocation(location);

locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}

private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}

public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}

public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};

private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
String addressString = "No address found";

if (location != null) {
// Update my location marker
positionOverlay.setLocation(location);

// Update the map location.
Double geoLat = location.getLatitude()*1E6;
Double geoLng = location.getLongitude()*1E6;
GeoPoint point = new GeoPoint(geoLat.intValue(),
geoLng.intValue());

mapController.animateTo(point);

double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;

double latitude = location.getLatitude();
double longitude = location.getLongitude();

Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(latitude,
longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);

for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");

sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n" + addressString);
}
}



(my position overlay class)
package com.paad.whereami;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.location.Location;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyPositionOverlay extends Overlay {

private final int mRadius = 5;

Location location;

public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}

@Override
public boolean onTap(GeoPoint point, MapView mapView) {
return false;
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();

if (shadow == false) {
// Get the current location
Double latitude = location.getLatitude()*1E6;
Double longitude = location.getLongitude()*1E6;
GeoPoint geoPoint;
geoPoint = new
GeoPoint(latitude.intValue(),longitude.intValue());

// Convert the location to screen pixels
Point point = new Point();
projection.toPixels(geoPoint, point);

RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
point.x + mRadius, point.y + mRadius);

// Setup the paint
Paint paint = new Paint();
paint.setARGB(250, 255, 255, 255);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);

Paint backPaint = new Paint();
backPaint.setARGB(175, 50, 50, 50);
backPaint.setAntiAlias(true);

RectF backRect = new RectF(point.x + 2 + mRadius,
point.y - 3*mRadius,
point.x + 65, point.y + mRadius);

// Draw the marker
canvas.drawOval(oval, paint);
canvas.drawRoundRect(backRect, 5, 5, backPaint);
canvas.drawText("Here I Am",
point.x + 2*mRadius, point.y,
paint);
}
super.draw(canvas, mapView, shadow);
}
}
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Re: where am i application stops unexpectedly

Postby tobix » Fri Jul 23, 2010 10:28 pm

Hi schofeild,

that's far to much code you posted. No one here will read it...
Code examples are great, but please just the relevant parts!

And I think no one can help you with these few information you gave.
Please check the debug console for any error caused by your app.
It's called logcat and can be found in Eclipse's DDMS-View.
tobix
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sun Jul 11, 2010 12:38 pm


Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests