3

I am using android studio 0.8.9. i am using google map v2 and google services 5.2.08.i want to display marker from given address and also generated SHA Key using key-tool also enabled and get my API Key from google console. But when i am using GeoPoint for getting Lat and Long android studio does not recognize GeoPoint class. My Java Activity code:

public class WelcomeUser extends ActionBarActivity {

GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome_user);


    try {
        if(null == googleMap){
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.mapView)).getMap();

            /**
             * If the map is still null after attempted initialisation,
             * show an error to the user
             */
            if(null == googleMap) {
                Toast.makeText(getApplicationContext(),
                        "Error creating map", Toast.LENGTH_SHORT).show();
            }
        }
    } catch (NullPointerException exception){
        Log.e("mapApp", exception.toString());
    }



    double lat= 0.0, lng= 0.0;

    String address = "Ahmedabad, Gujarat";
    Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
    try
    {
        List<Address> addresses = geoCoder.getFromLocationName(address , 1);
        if (addresses.size() > 0)
        {
            GeoPoint p = new GeoPoint(
                    (int) (addresses.get(0).getLatitude() * 1E6),
                    (int) (addresses.get(0).getLongitude() * 1E6));

            lat=p.getLatitudeE6()/1E6;
            lng=p.getLongitudeE6()/1E6;

            Log.d("Latitude", ""+lat);
            Log.d("Longitude", ""+lng);
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }


    if(null != googleMap){
        googleMap.addMarker(new MarkerOptions()
                        .position(p)
                        .title("Marker")
                        .draggable(true)
        );
    }

}

Please help me guys.Thanks in advance

Jayesh Ahir
  • 51
  • 1
  • 9

1 Answers1

1

Geocoder no longer provided latitude-longitude from addresses,use Reverse Geocoding API to get latitude-longitude from address.

Check Example here : Get latitude,longitude from address in Android

Community
  • 1
  • 1
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67