首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在标记信息窗口中提取并显示JSON数据,提取当前位置的位置类型

在标记信息窗口中提取并显示JSON数据,提取当前位置的位置类型
EN

Stack Overflow用户
提问于 2016-07-19 19:09:05
回答 1查看 573关注 0票数 0

我有两个自动完成来查找路线,我已经完成了两个位置的路线。我有起点和目的地marker.In,我设置了信息窗口来显示纬度,经度,位置,子位置,管理区域。我已经成功地显示了lat和lan.Now,我获取了Json数据并显示在信息窗口中。我已经解析了数据,但不知道如何在info window.suggest中显示它。

代码语言:javascript
运行
复制
    googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame

        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow

        public View getInfoContents(Marker arg0) {

            // Getting view from the layout file info_window_layout
            View v = getLayoutInflater().inflate(R.layout.info_window, null);

            // Getting the position from the marker
            LatLng latLng = arg0.getPosition();


            // Getting reference to the TextView to set latitude
            TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);

            // Getting reference to the TextView to set longitude
            TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
            TextView type=(TextView)v.findViewById(R.id.type);

            // Setting the latitude
            tvLat.setText("Latitude:" + latLng.latitude);

            // Setting the longitude
            tvLng.setText("Longitude:" + latLng.longitude);
            type.setText("locality"+"");


            // Returning the view containing InfoWindow contents
            return v;

        }
    });

 public void onDirectionFinderStart() {
    progressDialog = ProgressDialog.show(this, "Please wait.",
            "Finding direction..!", true);

    if (originMarkers != null) {
        for (Marker marker : originMarkers) {
            marker.remove();
            marker.showInfoWindow();

        }
    }

    if (destinationMarkers != null) {
        for (Marker marker : destinationMarkers) {
            marker.remove();
            marker.showInfoWindow();

        }
    }

    if (polylinePaths != null) {
        for (Polyline polyline : polylinePaths) {
            polyline.remove();
        }
    }
}


private class GetLocationTask extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... arg0) {
        // Creating service handler class instance
        ServiceHandler sh = new ServiceHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);
        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);

                JSONArray addrComp = jsonObj.getJSONArray("results");
                for (int i = 0; i < addrComp.length(); i++){
                    JSONObject ad=new JSONObject();
                    JSONArray addr = ad.getJSONArray("address_components");
                    for (i = 0; i < addr.length(); i++){
                        JSONObject ty=new JSONObject();
                        JSONArray typ=ty.getJSONArray("types");
                        for (i = 0; i < typ.length(); i++){
                            JSONObject c = typ.getJSONObject(i);
                            String locality=c.getString("locality");
                            String political=c.getString("political");
                            String sublocality=c.getString("sublocality");
                            String adminArea=c.getString("administrative_area_level_1");



                            /*HashMap<String, String> local = new HashMap<>();
                            local.put("locality",locality);
                            local.put("administrative_area_level_1",adminArea);
                            local.put("sublocality",sublocality);
                            local.put("political",political);

                            list.add(local);*/
                        }
                    }

                }

            }
            catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }

        return null;
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2016-07-19 19:12:16

您可以使用https://developers.google.com/maps/documentation/android-api/infowindows

http://androidfreakers.blogspot.in/2013/08/display-custom-info-window-with.html来实现需求。您需要为其创建自定义布局,并从适配器设置信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38456825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档