Skip to content Skip to sidebar Skip to footer

Parse Json Objects(lat And Lng) In Googlemap As Markers

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() a

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

Post a Comment for "Parse Json Objects(lat And Lng) In Googlemap As Markers"