最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android定位数据在移动,android

运维笔记admin74浏览0评论

android定位数据在移动,android

android定位数据在移动,android

我正在测试一款在三星平板电脑中借助GPS进行纬度和经度的应用程序。 我能够从GPS单元捕获当前的纬度,经度。 现在,我想使用纬度经度从这些位置获取地址,而无需使用Internet即wi-fi,移动数据。

我正在以以下方式进行操作:

public String getAddress(Context ctx, double latitude, double longitude) {

StringBuilder result = new StringBuilder();

try {

Geocoder geocoder = new Geocoder(ctx, Locale.getDefault());

List

addresses = geocoder.getFromLocation(latitude, longitude, 1);

if (addresses.size() > 0) {

Address address = addresses.get(0);

String locality=address.getLocality();

String city=address.getCountryName();

String region_code=address.getCountryCode();

String zipcode=address.getPostalCode();

double lat =address.getLatitude();

double lon= address.getLongitude();

result.append(locality+" ");

result.append(city+" "+ region_code+" ");

result.append(zipcode);

}

} catch (IOException e) {

Log.e("tag", e.getMessage());

}

return result.toString();

}

private class GetCurrentAddress extends AsyncTask {

@Override

protected String doInBackground(String... urls) {

// this lat and log we can get from current location but here we given hard coded

double latitude=12.916523125961666;

double longitude=77.61959824603072;

String address= getAddress(context, latitude, longitude);

return address;

}

@Override

protected void onPostExecute(String resultString) {

dialog.dismiss();

result.setText(resultString);

}

}

在mainfest中,我输入以下内容:

发布评论

评论列表(0)

  1. 暂无评论