Hi,
I am a bit new to ASP.net and trying to build an application that shows a list of interesting places: My code is as follows -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
namespace PlacesOfInterest.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
Places model = null;
var client = new HttpClient();
var task = client.GetAsync("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=52.5954328,-2.1313965&rankby=distance&types=electrician|electronics_store&key=My_API_KEY")
.ContinueWith((taskwithreponse) =>
{
var response = taskwithreponse.Result;
var readtask = response.Content.ReadAsAsync();
readtask.Wait();
model = readtask.Result;
});
task.Wait();
return View(model.results);
}
public ActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public ActionResult Error()
{
return View();
}
}
}
The other code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace PlacesOfInterest.Controllers
{
public class Places
{
public Place[] results;
}
public class Place
{
[JsonProperty("name")]
public string Placename { get; set; }
[JsonProperty("vicinity")]
public string Address { get; set; }
}
}