C#中的Google几何Api

C#中的Google几何Api,第1张

概述我有一个点(纬度,经度)ex:33.959295,35.606100我正在寻找一种方法在c#中检查这个点是否在特定路线(点列表或折线).我做了一些研究,我发现谷歌地图几何图书馆中包含的is​​LocationOnEdge功能正是我所需要的,但它不适用于c#.以下是其他语言的一些示例: > Google Map Javascript API https://developers.google.com 我有一个点(纬度,经度)ex:33.959295,35.606100我正在寻找一种方法在c#中检查这个点是否在特定路线(点列表或折线).我做了一些研究,我发现谷歌地图几何图书馆中包含的is​​LocationOnEdge功能正是我所需要的,但它不适用于c#.以下是其他语言的一些示例:

@H_301_8@

> Google Map Javascript API https://developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge.
> AndroID示例https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/PolyUtil.java
>我为gmaps google maps API for C#找到了一个c#库,但它不支持isLocationOnEdge函数@H_301_8@

有没有办法在c#中执行上面的要求?@H_301_8@解决方法 以下是IsLocationOnEdge For C#的实现.

@H_301_8@

@H_301_8@

using System;using System.Collections.Generic;using System.Device.Location;using System.linq;using System.Text;using System.Text.RegularExpressions;using System.Threading;using System.Threading.Tasks;namespace TestConsoleApp{    class Program    {        static voID Main(string[] args)        {            var path = new List<Location>            {                new Location(1,1),new Location(2,2),new Location(3,3),};            var point = new Location(1.9,1.5);            bool isOnEdge = isLocationOnEdge(path,point);            Console.ReadKey();        }        static bool isLocationOnEdge(List<Location> path,Location point,int tolerance = 2)        {            var C = new GeoCoordinate(point.Lat,point.Lng);            for (int i = 0; i < path.Count - 1; i++)            {                var A = new GeoCoordinate(path[i].Lat,path[i].Lng);                var B = new GeoCoordinate(path[i + 1].Lat,path[i + 1].Lng);                if (Math.Round(A.Getdistanceto(C) + B.Getdistanceto(C),tolerance) == Math.Round(A.Getdistanceto(B),tolerance))                {                    return true;                }            }            return false;        }    }    class Location    {        public Location(double Lat,double Lng)        {            this.Lat = Lat;            this.Lng = Lng;        }        public double Lat { get; set; }        public double Lng { get; set; }    }}

参考文献:@H_301_8@

Check is a point (x,y) is between two points drawn on a straight line
Calculating Distance between two Latitude and Longitude GeoCoordinates@H_301_8@ 总结

以上是内存溢出为你收集整理的C#中的Google几何Api全部内容,希望文章能够帮你解决C#中的Google几何Api所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1233162.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存