android 定位当前城市
2013-11-01 18:47
357 查看
private void getLocationByLocationManager() { LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateLocation(location); } public void onStatusChanged( String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); locationManager.removeUpdates(locationListener); } private void updateLocation(Location location){ currentLocation = location; currentLatitude = currentLocation.getLatitude(); currentLongitude = currentLocation.getLongitude(); try{ Geocoder gcd = new Geocoder(this, Locale.getDefault()); List<Address> addresses = gcd.getFromLocation(currentLatitude, currentLongitude,100); if (addresses.size() > 0) { StringBuilder result = new StringBuilder(); // for(int i = 0; i < addresses.size(); i++){ // Address address = addresses.get(i); // int maxIndex = address.getMaxAddressLineIndex(); // for (int x = 0; x <= maxIndex; x++ ){ // result.append(address.getAddressLine(x)); // result.append(","); // } // result.append(address.getLocality()); // result.append(","); // result.append(address.getPostalCode()); // result.append("\n\n"); // } result.append("AdminArea:"+addresses.get(0).getAdminArea()+","); result.append("SubAdminArea"+addresses.get(0).getSubAdminArea()+","); result.append("FeatureName"+addresses.get(0).getFeatureName()+","); result.append("Locality"+addresses.get(0).getLocality()+","); result.append("countryName"+addresses.get(0).getCountryName()+","); result.append("Premises"+addresses.get(0).getPremises()+","); result.append("SubLocality"+addresses.get(0).getSubLocality()+","); result.append("SubThoroughfare"+addresses.get(0).getSubThoroughfare()+","); result.append("Thoroughfare"+addresses.get(0).getThoroughfare()+","); LogUtil.e("NewLoc",result.toString()); } }catch(IOException ex){ } }
相关文章推荐
- Android利用百度定位SDK获取当前城市位置
- Android定位当前城市的实现
- android开发游记:集成百度定位SDK进行实时定位 获取当前城市地理信息
- android使用自定控件实现城市列表展示并且实现当前城市定位
- Android进阶之利用百度地图定位获取当前城市
- iOS 手机定位 获取当前城市
- js实现PC端根据IP定位当前城市地理位置
- Android 高德地图,显示地图,并定位当前的位置
- Android中通过当前经纬度获得城市
- 微信小程序城市定位的实现实例(获取当前所在国家城市信息)
- Android 端天气预报APP的实现(七)实现城市定位功能
- 基于百度定位获取当前城市请求天气信息
- Android 如何快速定位当前页面是哪个Activity or Fragment
- 微信小程序定位到当前城市
- iOS8及以后 地图定位当前城市
- 使用百度地图定位当前城市,在浏览器中可以,但是在安卓webview中定位失效
- Fragment中实现自动定位当前城市,点击刷新按钮更新天气信息
- iOS定位-利用CoreLocation.framework获取当前城市
- Android GPS定位,取得城市名称
- Android城市列表,首字母排序,右侧点击字母定位