我正在使用以下代码在android中设置mapview并显示效果良好的位置标记。
此外,我正在尝试使用maps.googleapis.com和我的api密钥来检索+显示附近的XML附近位置数据,或者使用Toast消息,或者在调试器中
我知道我不应该在主线程上运行HTTPrequest,但出于调试目的,我只是想确认我实际上正在检索所需的JSON数据
(它在浏览器中使用“https://maps.googleapis.com/maps/api/place/search/json?location=39.9165171,116.450872&radius=50&sensor=false&key=MYKEY”)例如
我无法解决Logcat中的主机错误
public class MainActivity extends MapActivity implements LocationListener {
MyLocationOverlay myLocationOverlay;
public MapView mapView;
MapController mc;
OverlayItem overlayitem;
List<Overlay> mapOverlays;
HelloItemizedOverlay itemizedoverlay;
GeoPoint myLocationGeoPoint;
String result = "nothing";
private MockGpsProvider mMockGpsProviderTask = null;
/* This method is called when use position will get changed */
public void onLocationChanged(Location location) {
final String TAG = getClass().getSimpleName();
String googleAPIKey = "xxxxxxxxx";
String searchRadius = "50";
String baseUrl = "https://maps.googleapis.com/maps/api/place/search/json?";
String lat = String.valueOf(location.getLatitude());
String lon = String.valueOf(location.getLongitude());
String url = baseUrl + "location=" + lat + "," + lon + "&" +
"radius=" + searchRadius + "&" + "sensor=false" +
"&" + "key=" + googleAPIKey;
Log.v(TAG,url);
Toast.makeText(this, url, Toast.LENGTH_LONG).show();
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
ResponseHandler<String> handler = new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
Log.v(TAG,result);
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}
答案 0 :(得分:-1)
没关系,通过执行异步任务+ json解析来弄明白