title: Android: My GPS application desn't display my correct location on the Google maps ? why?
body: <p>I'm using GPS to get my location but this code shows my location in Pacific although I'm in middle east ...</p>
  
  <p>another functionality of this code is to add an icon ( marker ) in the place I touch on the screen , according my code, does it works fine ?!</p>
  
  <p>here is my code :</p>
  
  <pre><code>package com.adhamenaya.android;
  
  import java.util.List;
  
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Canvas;
  import android.graphics.Point;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.view.MotionEvent;
  
  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;
  
  public class MapApp extends MapActivity {
  
      private MapView mapView;
      private MapController mapController;
      private LocationManager locationManager;
      private GeoPoint p;
      List&lt;Overlay&gt; listOfOverlays ;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          initLayout();
          initMap();
          listOfOverlays = mapView.getOverlays();        
      }
  
      private void initLayout(){
           mapView = (MapView) findViewById(R.id.mapview);
  
      }
      private void initMap(){
          mapView.setBuiltInZoomControls(true);
          mapView.setStreetView(true);
          mapController=mapView.getController();
          mapController.setZoom(10);// 1 is world view
          locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0, 0, new GeoUpdateHandler());
  
      }      
      @Override
      protected boolean isRouteDisplayed() {
          // TODO Auto-generated method stub
          return false;
      }
      class MapOverlay extends com.google.android.maps.Overlay
      {
          private GeoPoint p;
          private int res;
  
          public MapOverlay(GeoPoint p,int res){
              this.p=p;
              this.res=res;
          }
  
      @Override
       public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
       {
           super.draw(canvas, mapView, shadow);                   
  
           //---translate the GeoPoint to screen pixels---
           Point screenPts = new Point();
           mapView.getProjection().toPixels(p, screenPts);
  
           //---add the marker---
           Bitmap bmp = BitmapFactory.decodeResource(getResources(),res);            
           canvas.drawBitmap(bmp, screenPts.x, screenPts.y-20, null);         
           return true;
       }
  
          @Override
          public boolean onTouchEvent(MotionEvent event, MapView mapView) 
          {   
              //---when user lifts his finger---
              if (event.getAction() == 1) {                
                   GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY());
                   mapController.animateTo(p);
                   MapOverlay mapOverlay = new MapOverlay(p,R.drawable.redicon);
                   listOfOverlays.add(mapOverlay);        
                   mapView.invalidate();
              }                            
              return false;
          }        
      }
  
      class GeoUpdateHandler implements LocationListener {
  
          @Override
          public void onLocationChanged(Location location) {
              int lat=(int)(location.getLatitude()*1E6);
              int lng=(int)(location.getLongitude()*1E6);         
              GeoPoint p=new GeoPoint(lat,lng);
              mapController.animateTo(p);
              MapOverlay mapOverlay = new MapOverlay(p,R.drawable.blueicon);
              listOfOverlays.add(mapOverlay);        
              mapView.invalidate();
  
          }
  
          @Override
          public void onProviderDisabled(String arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onProviderEnabled(String arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
              // TODO Auto-generated method stub
  
          }
  
  }
  
  }
  </code></pre>