【问题标题】:How can I add these locations on the map from JSON?如何通过 JSON 在地图上添加这些位置?
【发布时间】:2019-05-09 23:39:59
【问题描述】:

我的项目运行,它已经显示了设备的当前位置。我的问题是有一个包含 4 个地址的 JSON。我应该在地图上添加这些地址。如何将这些位置添加到来自JSON 的地图?

此 JSON 的网站:https://instalyticsdbplandiag814.blob.core.windows.net/mobiversite/location.json

【问题讨论】:

    标签: java android json google-maps


    【解决方案1】:

    试试这个 sn-p:

        try {
            JSONObject jsonObject= new JSONObject(jsonAsString);
    
            JSONArray jsonArray=jsonObject.getJSONArray("locations");
    
            for(int i=0;i<jsonArray.length(); i++){
    
                JSONObject item = jsonArray.getJSONObject(i);
    
                String name=item.getString("name");
    
                String lattitude= item.getString("lattitude");
    
                String longitude= item.getString("longitude");
    
    
                //process as you want
            }
    
    
        } catch (JSONException e) {
            e.printStackTrace();
        }
    

    【讨论】:

    • 这本身就是另一个话题。为简单起见,您可以将此 json 添加到从 url 复制的 android assets 文件夹中
    • 好的。谢谢你的帮助。
    猜你喜欢
    • 2014-05-14
    • 2012-09-21
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2018-11-13
    • 2018-04-30
    • 1970-01-01
    相关资源
    最近更新 更多