简体   繁体   中英

JSON parsed to ArrayList. How can I get it to repeat data in onPostExecute for multiple map markers?

Title needs a bit more explanation. So I have lots of JSON that I have parsed and put into one ArrayList. The JSON is an Array of shops. The JSONObjects are the shops details, things like name, address, latitude, longitude etc.

Now in my onPostExecute I want to plot these as markers on a map and call the shops information when user clicks on a marker. I've got as far as being able to plot only one shop as a marker. The amount of shops I will have will change constantly over time, right now there are 4.

In my onPostExecute I have following code:

@Override
protected void onPostExecute(ArrayList<ShopArray> shopArray) {
    super.onPostExecute(shopArray);

    double lat = shopArray.get(0).geo_lat;
    double lng = shopArray.get(0).geo_lng;

    LatLng test = new LatLng(lat, lng);

    gMap.addMarker(new MarkerOptions()
        .position(test));

}

As of now my JSON has 4 shops listed, but it will only plot one on the marker. Is there a way I can call all the latitudes and longitudes and then have all the map markers show? If you need me to post my JSON let me now and I will update my post. This is sort of the final hurdle to get it shown to the user.

Would really appreciate some advice on where I have gone wrong or what can be done better. Thanks in advance!

@Override
protected void onPostExecute(ArrayList<ShopArray> shopArray) {
    super.onPostExecute(shopArray);

    for(ShopArray shopArrayObj : shopArray)
    { 
    double lat = shopArrayObj.geo_lat;
    double lng = shopArrayObj.geo_lng;

    LatLng test = new LatLng(lat, lng);

    gMap.addMarker(new MarkerOptions()
        .position(test));
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM