javascript - Geolocation not being called before chance to display -
javascript - Geolocation not being called before chance to display -
i trying distance between 2 locations , display them. have php request beingness called course of study information. on response, going through each course of study , adding global creating ui component.
however, having problem not beingness able info getdistancefromcurrentlocation function. seems not returning proper distance.
here "looping through data" code:
$.getjson( baseurl+"/getallcourses.php?callback=?", function( info ) { $.each(data, function() { var d = getdistancefromcurrentlocation(parsefloat(this['latitude']), parsefloat(this['longitude'])); console.log("d= " +d); listring += "<li><div class='cs_courselistleftgrid'><h3>"+this['coursename']+"</h3><p>par: "+this['par']+", "+this['holes']+" holes</p></div><div class='cs_courselistrightgrid'>"+d+"</div></li>"; var c = new course(this['courseid'] , this['coursename'], this['holes'], this['latitude'], this['longitude'] ); listofcourses.push(c); });
and here geolocation code:
function getdistancefromcurrentlocation(latitude, longitude) { console.log("latlong "+ latitude +", " +longitude); navigator.geolocation.getcurrentposition( function(position) { var latlnga = new google.maps.latlng(latitude, longitude); var currentlatlng = new google.maps.latlng(position.coords.latitude,position.coords.longitude); var distance = google.maps.geometry.spherical.computedistancebetween(latlnga, currentlatlng); console.log(distance); var mi = getdistance(distance, "miles"); console.log(mi); homecoming mi; }, function() { alert("please turn on location services total functionality!"); } ); } function getdistance (d, unit) { if (unit = "miles") { var mi = math.round( (d / 1609.34) * 10 ) / 10; homecoming mi; } }
the returned results chrome's console:
latlong 30.447578, -97.691451 main.js:598 d= undefined main.js:362 latlong 30.268064, -97.776807 main.js:598 d= undefined main.js:362 latlong 30.431718, -97.673132 main.js:598 d= undefined main.js:362 latlong 0, 0 main.js:598 d= undefined main.js:362 10762631.56763907 main.js:604 6687.6 main.js:606 3246.0764362640707 main.js:604 2 main.js:606 19512.13946601494 main.js:604 12.1 main.js:606 20687.592216616336 main.js:604 12.9
all info beingness processed, not in right order. how go waiting homecoming miles before moving onto next course of study in php data?
javascript php geolocation
Comments
Post a Comment