HTML and CSS Reference
In-Depth Information
Figure 12-7. Entity Framework data model for Jobs and Location tables
The Jobs table stores JobTitle , Description , and LocationName , whereas the Locations table stores
LocationName , Latitude , and Longitude . The code that performs the job of finding the user's location and
fetching the relevant job postings is shown in Listing 12-9.
Listing 12-9. Finding Job Postings Based on User Location and Ddistance
$(document).ready(function () {
$("#btnShow").click(function () {
window.navigator.geolocation.getCurrentPosition(function (position) {
var lat1 = position.coords.latitude;
var long1 = position.coords.longitude;
var distance = $("#txtDistance").val();
var data = '{ "lat1" : "' + lat1 + '","long1":"' + long1 +
'","distance":"' + distance + '"}';
$.ajax({
type: "POST",
url: '/home/GetJobs',
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (jobs) {
$("#tblJobs").empty();
$("#tblJobs").append("<tr><th>Job Title</th><th>Description</th><th>Location</th></
tr>");
for (var i = 0;i<jobs.length;i++)
{
$("#tblJobs").append("<tr><td>" + jobs[i].JobTitle + "</td><td>" +
jobs[i].Description + "</td><td>" + jobs[i].LocationName +
"</td></tr>");
}
},
error: function (err) {
alert(err.status + " - " + err.statusText);
}
});
 
Search WWH ::




Custom Search