jQuery を使用して、次の URL から JSON を取得しています。
http://api.chartbeat.com/live/geo/v3/?apikey=fakekeytoshowtheurl&host=example.com
以下は、取得した JSON の例です。
"lat_lngs": [[25, -80, 9], [26, -80, 6], [27, -80, 1], [29, -98, 2], [29, -95, 7], [30, -97, 3], [33, -117, 6], [33, -112, 25], [33, -111, 33], [34, -112, 1], [34, -111, 1], [36, -109, 1], [38, -97, 2], [40, -73, 1], [42, -78, 2]]
jQuery を使用して、lat_lngs のそれぞれを取得し、関数を実行しようとしています。
これが私が現在持っているコードで、動作していません。
function addMarker(latitude, longitude) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
map: map
});
}
$.get('http://api.chartbeat.com/live/geo/v3/?apikey=fakekeytoshowtheurl&host=example.com', function(data) {
$.each(data['lat_lngs'], function() {
var latlng = data['lat_lngs'].split(',');
addMarker(latlng[0], latlng[1]);
})
});
これは機能しません。オブジェクト [オブジェクト配列] に「分割」メソッドがありませんというエラーが表示され、何を試しても何も動作しません。リストされているすべての lat_lngs から最初の 2 つの数値を取得し、関数 addMarker(lat, long) を実行したいだけです。
誰にもアイデアがありますか?