Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am on the way of developing a Google map related service in android. I want to point out my current location in the map and have to mark the location in it. It will be alright when I am passing altitude and longitude maually into the map. But, when retrieving the lat & long with geocoder, i can't point it in the map, doing it forcefully results in the crushing of the app. Can anybody suggest a solution?

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

mapView = (MapView) findViewById(R.id.mapView);
mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);

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();

List<overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);


HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
OverlayItem overlayitem = new OverlayItem(point,"","" );
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);

}

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

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub

}

@Override
public void onProviderDisabled(String provider) {

Toast.makeText(getBaseContext(),"GPS Disabled",Toast.LENGTH_SHORT).show();

}

@Override
public void onProviderEnabled(String provider) {

Toast.makeText(getBaseContext(),"GPS Enabled",Toast.LENGTH_SHORT).show();

}

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

}

This is my code
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900