【问题标题】:Android maps.googleapis.com, issues retrieving JSON data [closed]Android maps.googleapis.com,检索 JSON 数据的问题 [关闭]
【发布时间】:2012-10-10 05:44:23
【问题描述】:

我正在使用以下代码在 android 中设置地图视图并显示位置标记,效果很好。

此外,我正在尝试使用 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();
}

【问题讨论】:

    标签: android debugging google-maps httprequest google-places-api


    【解决方案1】:

    没关系,通过异步任务+json解析解决

    【讨论】:

    • 这不是一个答案,请更详细地说明是什么导致您找到可能的解决方案。即使我面临同样的问题。
    猜你喜欢
    • 2019-12-18
    • 1970-01-01
    • 2015-04-24
    • 2015-08-29
    • 1970-01-01
    • 2020-03-18
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多