Parse JSON objects(lat and lng) in GoogleMap as ma

2019-09-29 14:29发布

问题:

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) ));
    }
}