我有这堂课:
{"error":{"type":"ErrorException","message":"Undefined variable: slideshow","file":"\/Applications\/MAMP\/htdocs\/project\/app\/controllers\/ContactCentreSlideshowController.php","line":24}}
我可以看到地图,但地点上没有文字。
答案 0 :(得分:0)
//You need to create a location manager object and request location updates or getlastknownlocation
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 2000, 0, this);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 2000, 0, this);
} catch (java.lang.SecurityException ex) {
Log.i("", "fail to request location update, ignore", ex);
} catch (IllegalArgumentException ex) {
Log.d("", "network provider does not exist, " + ex.getMessage());
}
答案 1 :(得分:0)
使用LocationManager
访问位置相关数据并通过以下方式实例化:
LocationManager mLocationmanager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
从NETWORK_PROVIDER
或GPS_PROVIDER
获取位置对象。我建议从networkprovider获取位置数据,因为我使用的电池少于GPS(按照android official document)。
现在通过致电
获取您的位置Double mUserlatitude = location.getLatitude();
Double mUserlongitude = location.getLongitude();
完整代码段如下:
LocationManager mLocationmanager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
Location location = mLocationmanager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Double mUserlatitude = location.getLatitude();
Double mUserlongitude = location.getLongitude();
Log.d("Latitude",""+mUserlatitude);
Log.d("Latitude",""+mUserlongitude );