json - Calculate driving distance between user location and many destinations via javascript loop -


i have json feed many locations:

http://hcafeeds.medcity.net/rss/er/ntx_rss_feed.xml

i plan on obtaining user's location via html5 geolocation. @ point, i'd loop through json feed , output items feed along distance user's location.

i've tried every way can google maps api seem hit hurdle hour method.

has done similar?

update: here's existing code

will output hospitals fine... can't figure out how distance:

  var hcafeed = 'http://hcafeeds.medcity.net/rss/er/ntx_rss_feed.xml';   var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeuricomponent('select * rss url="' + hcafeed + '"') + '&format=json&diagnostics=true&callback=?';   $.getjson(yql,function(data){     if(data.query.count > 0) {        // run through hospitals , set html       var hospitals = [];       $.each( data.query.results.item, function( key, val ) {         var hospitaladdress = val.address;         var wait = $.trim(val.description.replace("mins",""));         var units = (wait == 1) ? " min" : " mins";          hospitals.push({           'name' :        "<div class='name'>"+val.comments.replace(" er wait time","")+"</div>",           'addy' :        "<div class='addy'>"+val.address+"</div>",           'phone' :       "<div class='phone'>"+val.phone+"</div>",           'waitoutput' :  "<div class='wait'>"+wait+units+"</div>",           'wait' :        wait,           'distanceoutput' : "<div class='distance'></div>",         });        });        // sort array wait time (default)       hospitals.sort(function(a, b){         return a.wait-b.wait;       });        // prepare array output (wrapper)       var output = [];       $.each( hospitals, function( key, val ) {         output.push("<div data-key='"+key+"' data-wait='"+val.wait+"' class='hospital'>"+val.name+val.addy+val.phone+val.waitoutput+val.distanceoutput+"</div>");       });     }      // print array     $("#hospitals").html( output );    }).fail(function (j, t, e) {      console.error(e);   }); 

i've created fiddle: https://jsfiddle.net/potd25yy/3/

rather distance matrix, should use directions service in google maps javascript api calculate path between user's location , hospital.

the function:

directionsservice.route(request, function(response, status) {         if (status == google.maps.directionsstatus.ok) { 

return response, multiple routes. , distance of first route be:

response.routes[0].legs[0].distance.text 

so can display corresponding entry.

i create quick demo calculate distance google, inc. each hospital. hope help. , let me know if have further questions.

https://jsfiddle.net/jqw3g914/1/


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -