Android: How to get Address from geolocation using Geocoder
来源:互联网 发布:传智播客全套java云盘 编辑:程序博客网 时间:2024/04/28 17:44
Class: HttpRetriever
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public
class
HttpRetriever {
private
DefaultHttpClient client =
new
DefaultHttpClient();
public
String retrieve(String url) {
HttpGet getRequest =
new
HttpGet(url);
try
{
HttpResponse getResponse = client.execute(getRequest);
final
int
statusCode = getResponse.getStatusLine().getStatusCode();
if
(statusCode != HttpStatus.SC_OK) {
Log.w(getClass().getSimpleName(),
"Error "
+ statusCode
+
" for URL "
+ url);
return
null
;
}
HttpEntity getResponseEntity = getResponse.getEntity();
if
(getResponseEntity !=
null
) {
return
EntityUtils.toString(getResponseEntity);
}
}
catch
(IOException e) {
getRequest.abort();
Log.w(getClass().getSimpleName(),
"Error for URL "
+ url, e);
}
return
null
;
}
}
Method: getAddressFromGPSData
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public
static
final
String GOOGLE_GEOCODER =
"http://maps.googleapis.com/maps/api/geocode/json?latlng="
;
public
static
String getAddressFromGPSData(
double
lat,
double
longi) {
HttpRetriever agent =
new
HttpRetriever();
String request = GOOGLE_GEOCODER + lat +
","
+ longi +
"&sensor=true"
;
// Log.d("GeoCoder", request);
String response = agent.retrieve(request);
String formattedAddress =
""
;
if
(response !=
null
) {
Log.d(
"GeoCoder"
, response);
try
{
JSONObject parentObject =
new
JSONObject(response);
JSONArray arrayOfAddressResults = parentObject
.getJSONArray(
"results"
);
JSONObject addressItem = arrayOfAddressResults.getJSONObject(
0
);
formattedAddress = addressItem.getString(
"formatted_address"
);
}
catch
(JSONException e) {
e.printStackTrace();
}
}
// Log.d("GeoCoder", response);
return
formattedAddress;
}
0 0
- Android: How to get Address from geolocation using Geocoder
- How to Get Mac Address
- How to get kernel messages from Android?
- How to set IP address using Qt
- how to get current tss address
- how to get toolchain from android source -make windows sdk
- How to get the Values of Selected Row from a Gridview using ASP.NET
- How to get simple dispatch from this.props using connect w/ Redux?
- How to Get Hardware Information using C#
- How to get file from classpath
- How to get parameters from the URL?
- How to get IHTMLDocument2 from a HWND
- How to get bean from tag component
- How to get byte array from imageview
- How to get UITableView from UITableViewCell?
- How to get UITableView from UITableViewCell?
- How to get source code from APK
- How to get local machine name and IP address?
- Spring和Mybatis整合时无法读取properties的处理方案
- 理解A*寻路算法具体过程
- 循环-28. 求给定序列前N项和之六(15)
- CUDA系列学习(五)GPU基础算法: Reduce, Scan, Histogram
- Android 编程下的 TraceView 简介及其案例实战
- Android: How to get Address from geolocation using Geocoder
- 为什么寄存器和内存访问带宽差这么多?
- java实现map和object互转的三种方法
- 备用数据的问题集锦
- Android实现推送消息方式解决方案
- 用jquery实现换肤的效果
- 前台javascript[js]产生Guid
- IOS开发2
- console.log解析