Hey all,
Trying to get a map to show up with points read from Json, an example of what the coding looks like is this:{"earthquakes":[{"eqid":"c0001xgp","magnitude":8.8,"lng":142.369,"src":"us","datetime":"2011-03-11 04:46:23","depth":24.4,"lat":38.322},{"eqid":"2007hear","magnitude":8.4,"lng":101.3815,"src":"us","datetime":"2007-09-12 09:10:26","depth":30,"lat":-4.5172},{"eqid":"2007aqbk","magnitude":8,"lng":156.9567,"src":"us","datetime":"2007-04-01 18:39:56","depth":10,"lat":-8.4528},{"eqid":"2007hec6","magnitude":7.8,"lng":100.9638,"src":"us","datetime":"2007-09-12 21:49:01","depth":10,"lat":-2.5265},{"eqid":"a00043nx","magnitude":7.7,"lng":100.1139,"src":"us","datetime":"2010-10-25 12:42:22","depth":20.6,"lat":-3.4841},{"eqid":"2010utc5","magnitude":7.7,"lng":97.1315,"src":"us","datetime":"2010-04-06 20:15:02","depth":31,"lat":2.3602},{"eqid":"2009mebz","magnitude":7.6,"lng":99.9606,"src":"us","datetime":"2009-09-30 08:16:09","depth":80,"lat":-0.7889},{"eqid":"2009kdb2","magnitude":7.6,"lng":92.9226,"src":"us","datetime":"2009-08-10 17:55:39","depth":33.1,"lat":14.0129},{"eqid":"2010zbca","magnitude":7.6,"lng":123.533,"src":"us","datetime":"2010-07-23 20:51:11","depth":576.3,"lat":6.4939},{"eqid":"2010xkbv","magnitude":7.5,"lng":91.9379,"src":"us","datetime":"2010-06-12 17:26:50","depth":35,"lat":7.7477}]}
Here is my code i have been using for this:
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(32.7153, -117.1564);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var north = results[0].geometry.location.lat() + 1;
var south = results[0].geometry.location.lat() - 1;
var east = results[0].geometry.location.lng() + 1;
var west = results[0].geometry.location.lng() - 1;
var quakeloc = 'http://api.geonames.org/earthquakesJSON?north=' + north + '&south=' + south + '&east=' + east + '&west=' + west + '&\
username=********';
map.setCenter(results[0].geometry.location);
$.getJSON(quakeloc, function(data){
$.each(data, function(key, val){
for(var i = 0; i <data.quakeloc.length; i++)
var location = new google.maps.LatLng(val[i].lat, val[i].lng);
var marker = new google.maps.Marker({
map: map,
position: location
title:'Magnitude: ' + val[i].magnitude + ' Depth: ' + val[i].depth + ' Date: ' + val[i].datetime
});
}
});
});
}
else {
else {
alert("Geocode was not successful for the following reason: " + status);
}
}
}
`
It all works until i get to reading the Json Data. I have commented code out little by little to see where it messages up at. Once i get to$.getJSON(quakeloc, function(data){
the script takes a turn for the worst. Any help would be great. ALSO if angone give me some pointers on adding info bubbles that would be great too.
Thanks All.