/// <summary> /// Compute the area (in square km) of the region with a border determined by nodes. /// </summary> public static double ComputeArea(IEnumerable <IGeoLocation> nodes, string apiKey) { var template = File.ReadAllText(Path.Combine("HtmlTemplates", "ComputeAreaTemplate.html")); var html = new StringBuilder(template); html.Replace("/*key*/", apiKey); var nodesStrings = GetNodesStrings(nodes, 16); html.Replace("/*nodes*/", string.Join($",{Environment.NewLine}", nodesStrings)); var area = JavaScriptHelper.ExecuteAndRead(html.ToString(), "area"); return(area / 1E6); }
public static IGeoLocation ComputeOffset(IGeoLocation start, int distance, double heading, string apiKey) { var template = File.ReadAllText(Path.Combine("HtmlTemplates", "ComputeOffsetTemplate.html")); var html = new StringBuilder(template); html.Replace("/*key*/", apiKey); html.Replace("/*startLat*/", start.Latitude.ToString()); html.Replace("/*startLon*/", start.Longitude.ToString()); html.Replace("/*distance*/", distance.ToString()); html.Replace("/*heading*/", heading.ToString()); var coordinates = JavaScriptHelper.ExecuteAndRead(html.ToString(), new string[] { "latitude", "longitude" }); return(new GeoLocation() { Latitude = coordinates["latitude"], Longitude = coordinates["longitude"] }); }