简体   繁体   中英

JQuery $.each returning same data set twice

I'm building an Instagram mapping app and I'm trying to iterate through the returned JSON using $.each. I'm currently testing it by returning the coordinates of the picture into a <div> . It's working wonderfully, except the same data shows up twice. Here is the statement (the commented-out code is for putting it on the map):

$.each(photos.data, function (index, photo) {
    if (photo.location) {
        /* var photocoords = google.maps.LatLng(photo.location.latitude,location.longitude);
                                var marker = new google.maps.Marker({
                                    position: photocoords,
                                    map: map,
                                    title: 'Test'
                                            });//end new marker


                                    */
        photo = photo.location.latitude + ' , ' + photo.location.longitude + '<br>';

        $('#photos-wrap').append(photo);
    } //end if
    else {
        return true
    }
});

And the data it's returning:

38.9232268 , -77.0464289
35.046506242 , -90.025382579
35.189142533 , -101.987259233

38.9232268 , -77.0464289
35.046506242 , -90.025382579
35.189142533 , -101.987259233

Thanks for any help you can provide.

change your code to this one

    var new_photo = photo.location.latitude + ' , ' + photo.location.longitude + '<br>';
    $('#photos-wrap').append(new_photo);

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