android中的地理定位
我的问题可能与此无关,但我想知道我是否可以在android中使用此api。您不能在android中使用此api,但可以在phonegap技术中使用此api。phonegap技术是一种跨平台的混合应用程序,我们可以在该应用程序中开发此api 步骤1:使用提供的服务连接方法检查Google Play服务是否可用。 步骤2:确保您已经实现了淋浴ROR对话框方法以及ErrorDialog片段 第三步:找到经纬度。android中的地理定位,android,w3c-geolocation,Android,W3c Geolocation,我的问题可能与此无关,但我想知道我是否可以在android中使用此api。您不能在android中使用此api,但可以在phonegap技术中使用此api。phonegap技术是一种跨平台的混合应用程序,我们可以在该应用程序中开发此api 步骤1:使用提供的服务连接方法检查Google Play服务是否可用。 步骤2:确保您已经实现了淋浴ROR对话框方法以及ErrorDialog片段 第三步:找到经纬度。 如果您需要更多信息,请参阅第页的我的答案。这里有一个例子。通过android,你是指本机a
如果您需要更多信息,请参阅第页的我的答案。这里有一个例子。通过android,你是指本机android应用程序还是Phonegap应用程序?@PurpleDroid我是指本机android应用程序。你只是想找到你当前的位置吗?@SeahawksRdaBest是的。@ShishupalShakya请看下面我的答案。有什么方法可以在android上使用吗。相反,你可以在android中使用locationManager……你可以按照本教程在android中使用地图,别忘了投票/接受。如果这有用:)@SeahawksRdaBest,目前我正在做同样的事情来获取当前位置,但我想使用地理位置api做同样的事情,因为它需要wifi和手机发射塔来获取位置状态。@ShishupalShakya在这种情况下,请特别使用位置管理器。getLastKnownLocation方法将返回一个Location对象。然后可以从该对象检索纬度和经度。
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;
}
}
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;
}
}
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();
}
}