I add the PlacePicker
widget to my application and now i'm able to get selected location latitude and longitude.
With this code:
public class TravelFragment extends Fragment {
int PLACE_PICKER_REQUEST = 1;
TextView lat;
TextView lng;
public TravelFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final FragmentActivity activity = getActivity();
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_travel, container, false);
lat = (TextView) view.findViewById(R.id.latitudeValue);
lng = (TextView) view.findViewById(R.id.longitudeValue);
Button findLocation = (Button) view.findViewById(R.id.buttonSearchLocation);
findLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(activity), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
double arrivalLat;
double arrivalLng;
String stringLat;
String stringLng;
Place place = PlacePicker.getPlace(data, getActivity());
arrivalLat = place.getLatLng().latitude;
arrivalLng = place.getLatLng().longitude;
stringLat = Double.toString(arrivalLat);
stringLng = Double.toString(arrivalLng);
lat.setText(stringLat);
lng.setText(stringLng);
String toastMsg = String.format("Place: %s", place.getLatLng());
// place.getLatLng();
Toast.makeText(getActivity(), toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
And if i well understand this is the same thing to use HTTP request to google maps for get near place?
But i see in the map that the Picker find my device with a blue dot, i would like to know if it possible to get the coordinates of my device or i need something else for getting device coordinates.
If i need something else for retrieve device position which is the best way for doing that by using 3G connection and GSP?
Anyway for getting Km distance and time travel the only way is to use the HTTP request?