3
我使用以下代碼在android中設置mapview並顯示位置標記,效果很好。Android maps.googleapis.com,檢索JSON數據的問題
另外我想用maps.googleapis.com與我的API密鑰來檢索+顯示附近XML附近位置數據,無論是與吐司消息或在調試器
我知道我不應該運行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();
}
這不是一個答案請以什麼促使你可能fix.Even我面臨同樣的問題更具描述。 – Nezam