using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace PositioningWebApp.Services
{
	public class PointLocation
	{
		public string Get(double Lat, double Lng)
		{
			string[] array = new string[] { Lat.ToString().Replace(",", "."), Lng.ToString().Replace(",", "."), "AIzaSyAmZrJ6NsLlovYi8bJtEtdDb7eIkmR7RnY" };
			string url = string.Format("https://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&key={2}", array);
			
			WebRequest request = WebRequest.Create(url);
			WebResponse response = request.GetResponse();
			XDocument xdoc = XDocument.Load(response.GetResponseStream());

			XElement result = xdoc.Element("GeocodeResponse").Element("result");
			XElement address = result.Element("formatted_address");
			response.Close();
			return address.Value;
		}
	}
}
