When I parse the lat and lng in System.out.println(shop.getShopLat()); works fine. And the Map without marker works fine. Now I want to add several marker using shop.getShopLat() and shop.getShopLng(). But when I tried to implement this getting redflags: The constructor LatLng(ArrayList, ArrayList) is undefined Someone please help to solve this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Please have a look at this line:
for(Shop shop : this.response.shops){
map.addMarker(new MarkerOptions().position(new LatLng(shop.getShopLat(), shop.getShopLng())).title(shop.getShopAddress()));
}
In this line you want to create a new LatLng() object by adding into constructor an array instead of one value, change this line into:
for(Shop shop : this.response.shops){
//remember to check is shop.getShopLat() is not null etc..
for(int i = 0; i < shop.getShopLat().size(); i++){
map.addMarker(new MarkerOptions().position(new LatLng( shop.getShopLat().get(i), shop.getShopLng().get(i) )).title( shop.getShopAddress().get(i) ));
}
}