My question may be irrelevant but I want to know can I use this api in android
.
Asked
Active
Viewed 165 times
0

Ullas
- 11,450
- 4
- 33
- 50
-
There is an example. By android, you mean native android app or Phonegap app? – MysticMagicϡ Jul 08 '14 at 05:12
-
@PurpleDroid I mean native android app. – Jul 08 '14 at 05:20
-
Do you just want to find your current location? – SeahawksRdaBest Jul 08 '14 at 05:27
-
@SeahawksRdaBest yes . – Jul 08 '14 at 05:52
-
@ShishupalShakya please see my answer below. – SeahawksRdaBest Jul 08 '14 at 05:56
2 Answers
1
Here is my approach using Location api in android.
Step 1: Use the Services connected method provided to check if Google Play Servcies are available.
private boolean servicesConnected() {
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getActivity());
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d(LocationUtils.APPTAG,
getString(R.string.play_services_available));
// Continue
return true;
// Google Play services was not available for some reason
} else {
// Display an error dialog
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode,
getActivity(), 0);
if (dialog != null) {
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
errorFragment.setDialog(dialog);
errorFragment.show(myContext.getSupportFragmentManager(),
LocationUtils.APPTAG);
}
return false;
}
}
Step2: Make Sure you've implemented the ShowError Dialog Method along with the ErrorDialog Fragment
private void showErrorDialog(int errorCode) {
// Get the error dialog from Google Play services
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
getActivity(),
LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment in which to show the error dialog
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);
// Show the error dialog in the DialogFragment
errorFragment.show(myContext.getSupportFragmentManager(),
LocationUtils.APPTAG);
}
}
/**
* Define a DialogFragment to display the error dialog generated in
* showErrorDialog.
*/
@SuppressLint("ValidFragment")
public class ErrorDialogFragment extends DialogFragment {
// Global field to contain the error dialog
private Dialog mDialog;
/**
* Default constructor. Sets the dialog field to null
*/
@SuppressLint("ValidFragment")
public ErrorDialogFragment() {
super();
mDialog = null;
}
/**
* Set the dialog to display
*
* @param dialog
* An error dialog
*/
public void setDialog(Dialog dialog) {
mDialog = dialog;
}
/*
* This method must return a Dialog to the DialogFragment.
*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
return mDialog;
}
}
Step 3: Find the Latitude & Longitude.
public void getAddress(View v) {
// In Gingerbread and later, use Geocoder.isPresent() to see if a
// geocoder is available.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD
&& !Geocoder.isPresent()) {
// No geocoder is present. Issue an error message
Toast.makeText(getActivity(), R.string.no_geocoder_available,
Toast.LENGTH_LONG).show();
return;
}
if (servicesConnected()) {
// Get the current location
Location currentLocation = mLocationClient.getLastLocation();
Lat = currentLocation.getLatitude();
Lng = currentLocation.getLongitude();
LatLng = Double.toString(Lat) + "," + Double.toString(Lng);
// Show the location in a toast message
Toast.makeText(getActivity(), LatLng, 0).show();
} else {
Toast.makeText(getActivity(), "servicesConnected() == false",
Toast.LENGTH_SHORT).show();
}
}
If you need more information please refer to my answer on this page.

Community
- 1
- 1

SeahawksRdaBest
- 868
- 5
- 17
-
-
@ SeahawksRdaBest , currently I am doing same thing to fetch current location but I want to do same thing using geolocation api since it requires wifi and cell towers to fetch location status . – Jul 08 '14 at 06:22
-
@ShishupalShakya in that case use Location Manager, specifically http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String). The the getLastKnownLocation method will return a Location object. From this object you can then retrieve the Latitude and Longitude. – SeahawksRdaBest Jul 08 '14 at 06:30
0
You can't use this api in android but you can use this api in phonegap technology which is cross platform Hybrid application where we can develop

vinay Maneti
- 1,447
- 1
- 23
- 31
-
-
-
you can follow this tutorial to have maps in android http://codebybrian.com/2012/12/06/google_maps_android_v2_sample.html,http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ – vinay Maneti Jul 08 '14 at 05:32