I have a address name , i want to get the Latitude and Longitude from my app , i reference some tutorial , i still can't get it successfully in the end.
The log value is empty.
What step i miss it ? any help would be grateful,thanks.
global variable:
double editLatitude, editLongitude;
my Geocoder:
Geocoder coder = new Geocoder(getActivity());
List<Address> address;
try {
address = coder.getFromLocationName("Las Vegas", 5);
if (address == null) {
return null;
}
Address location = address.get(0);
editLatitude = location.getLatitude();
editLongitude = location.getLongitude();
Log.d("editLatitude", editLatitude + ">>>>>>>>>>>>>>>>>>");
Log.d("editLongitude", editLongitude + ">>>>>>>>>>>>>>>>>>");
} catch (IOException ex) {
ex.printStackTrace();
}
i set the latitude and longitude over here:
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
//LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
//LatLng latLng = new LatLng(22.751262, 121.140801);
//---------------------------------------------
LatLng latLng = new LatLng(editLatitude, editLongitude);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
//move map camera
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(16));
//optionally, stop location updates if only current location is needed
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}