javascript - Calling geonames to find nearby streets -
i'm trying list of nearby streets given latlng value using geonames web service. can nearby wikopedia articles unable list of street names using findnearbystreetsosm method. have: i'm blind , using screenreader. code indented correctly.
//geonames api function //feed in geonames method i.e. findnearbywikipedia, findnearbystreetsosm + long , lat values + name of div want results displayed in function fetchdatafromgeonames(geonamesmethod, latitude, longitude, divtooutputresultsto) { var geonamesapikey = "my_api_key); var apiurl = "http://api.geonames.org/"; var radius = 1; var request = apiurl + geonamesmethod + "json?lat=" + latitude + "&lng=" + longitude + "&username=" + geonamesapikey; if (geonamesmethod == 'findnearbywikipedia') { request += "&radius=" + radius + "&maxrows=5&country=uk"; } request += '&callback=?'; //alert(request); //pass request onto geonames api $.getjson(request, {}, function(res) { if (res.hasownproperty("status")) { $("#divtooutputresultsto").html("sorry, failed work because: " + res.status.message); return; } var s = ""; //loop through results (var = 0; < res.geonames.length; i++) { //alert(json.stringify(res)); //if find wikopedia request if (geonamesmethod == 'findnearbywikipedia') { s += "<p><h2>" + res.geonames[i].title; } else if (geonamesmethod == 'findnearbystreetsosm') { s += "<p><h2>" + res.geonames[i].name; } if (geonamesmethod == 'findnearbywikipedia') { if(res.geonames[i].hasownproperty("thumbnailimg")) s += "<img src='"+res.geonames[i].thumbnailimg+"' align='left'>"; if (!!res.geonames[i].feature && res.geonames[i].feature != "undefined") s += '<br />feature: ' + res.geonames[i].feature; s += '<br />' + res.geonames[i].summary; s += "<br clear='left'><a href='http://"+res.geonames[i].wikipediaurl+"'>[read more]</a></p>"; } else if (geonamesmethod == 'findnearbystreetsosm') { s += '<br />highway: ' + res.geonames[i].highway; } } //concatonate results if (s != "") { if (geonamesmethod == 'findnearbywikipedia') { s = "<h2>nearby wikopedia</h2>" + s; } else if (geonamesmethod == 'findnearbystreetsosm') { s = "<h2>nearby streets (osm)</h2>" + s; } //display results on screen $(divtooutputresultsto).html(s); } }); }
thanks,
Comments
Post a Comment