Skip to content Skip to sidebar Skip to footer

JQuery To Parse Data And Get The Lat And Lng And Insert Into Google Maps`

I am using jQuery to get JSON from the following URL: http://api.chartbeat.com/live/geo/v3/?apikey=fakekeytoshowtheurl&host=example.com Here is an example of the JSON I get: '

Solution 1:

$.each(data['lat_lngs'], function(index, value) {
    addMarker(value[0], value[1]);
})

Explanation: data['lat_lngs'] is an array of arrays. When you iterate over it using $.each, each iteration receives as its value one element of the data['lat_lngs'] array.

And each element is itself an array. (Not a string! No need to split() anything.)

$.each also sets the this value to equal the current iteration’s value. So you could do this as well:

$.each(data['lat_lngs'], function() {
    addMarker(this[0], this[1]);
})

Post a Comment for "JQuery To Parse Data And Get The Lat And Lng And Insert Into Google Maps`"