次のコードを使用して、アンドロイドでマップビューをセットアップし、うまく機能する位置マーカーを表示しています。
さらに、APIキーでmaps.googleapis.comを使用して、トーストメッセージまたはデバッガーで近くの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();
}