您好我目前在Android中使用Google地图。我从mysql数据库中检索了纬度,经度和片段值的列表,并尝试在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)
);
}
}
我得到的纬度是未解决的类型。任何人都可以告诉我我错在哪里?
答案 0 :(得分:1)
试试这种方式
LatLng pinLocation = new LatLng(Double.parseDouble(vehiclehistory1.get(i).latitude), Double.parseDouble(vehiclehistory1.get(i).longitude));
而不是Parse Float使用Double
Latitude
和Longitude