Search code examples
androidgoogle-mapsgoogle-maps-api-2

Google map doesn't show correct location


Not so long ago I updated my map class on my app to use Google Maps Android API v2. In my app I use the class Location to save my current location. when I tried to add a marker with my location on the map with the code:

Log.e(tag,"adding user_marker at lat = " + Common.curLocation.getLatitude() 
+ ",lng = " + Common.curLocation.getLongitude());
User_Curr_Position = new LatLng(Common.curLocation.getLatitude(),
  Common.curLocation.getLatitude());
mUser_Curr_Position_Marker = mMap.addMarker(new 
MarkerOptions().position(User_Curr_Position).title("Your Position").draggable(true));

it gave me the wrong location (somewhere in the deep sea). I checked that I am not entering the wrong parameter by taking the lat and long from the Log ("adding user_marker at lat=32.165603,lng=34.81224") and found the right location on google maps (on the internet). Can someone tell me what am I doing wrong ?


Solution

  • Well, you are passing in the user's latitude in as the longitude.

    User_Curr_Position = new LatLng(Common.curLocation.getLatitude(),  Common.curLocation.getLatitude());
    

    It needs to be

    User_Curr_Position = new LatLng(Common.curLocation.getLatitude(),  Common.curLocation.getLongitude());