【问题标题】:Google Maps loading multiple markers from asynctask谷歌地图从异步任务加载多个标记
【发布时间】:2014-07-16 12:14:25
【问题描述】:

您好,我目前正在 Android 中使用 Google 地图。当我从 mysql 数据库中检索纬度、经度和 sn-p 值列表并尝试在 Google 地图中显示它时。这是我现在尝试的代码,但我没有在地图中得到标记,

public static ArrayList<HashMap<String,Double>> vehiclehistory1= new ArrayList<HashMap<String,Double>>();
double latitude;
double longitude;
for(int i=0;i<user.length();i++)
{
    System.out.println("forloop i valuie"+i);
    JSONObject c1 = user.getJSONObject(i);
    JSONObject c2 = c1.getJSONObject(TAG_SRES);

    vehicle_reg_numb = c2.getString(TAG_Vechicle_REG);
    latitude= c2.getDouble(TAG_Latitude);
    longitude = c2.getDouble(TAG_Longitude);
    speed = c2.getString(TAG_Speed);
    exceed_speed_limit=c2.getString(TAG_Exceed_Speed);
    bus_tracking_timestamp = c2.getString(TAG_bus_tracking_timestamp);
    address=c2.getString(TAG_address);
    map1.put(TAG_Latitude,latitude);
    map1.put(TAG_Longitude,longitude);
    map.put(TAG_Speed, speed);
    map.put(TAG_address, address);

    vehiclehistory1.add(map1);
    vehiclehistory.add(map);

}
@Override
protected void onPostExecute(String file_url) {

    super.onPostExecute(file_url);
    cDialog.dismiss();
    for (int i = 0; i < vehiclehistory1.size(); i++) {
        LatLng pinLocation = new LatLng(Float.parseFloat(vehiclehistory1.get(i).latitude), Float.parseFloat(vehiclehistory1.get(i).longitude));
        Marker storeMarker = map.addMarker(new MarkerOptions()
            .position(pinLocation)
            .title(vehiclehistory1.get(i).pinname)
            .snippet(vehiclehistory1.get(i).address)
        );
    }
}

我得到纬度是未解决的类型。谁能告诉我我做错了什么?

【问题讨论】:

    标签: android mysql google-maps android-asynctask


    【解决方案1】:

    试试这个方法

      LatLng pinLocation = new LatLng(Double.parseDouble(vehiclehistory1.get(i).latitude), Double.parseDouble(vehiclehistory1.get(i).longitude));
    

    使用 Double 代替 Parse Float 用于 LatitudeLongitude

    【讨论】:

    • @M.D 谢谢..我也试过了。我得到的纬度和经度都应该无法解析或者它不是字段
    • @micky 您是否将纬度和经度存储为字符串?
    • @micky 那么不需要在 Double 中解析它。
    • @micky 试试这个LatLng pinLocation = new LatLng(vehiclehistory1.get(i).latitude, vehiclehistory1.get(i).longitude);
    • @D.K 我试过了,但还是一样的 prblm...抱歉寻求更多帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    相关资源
    最近更新 更多