Geocoordinate does not contain a definition for Getdistanceto

Asked

Viewed 160 times

1

I’m trying to make an algorithm that calculates the distance between two points from their coordinates (Latitude and Longitude), in my researches I ended up coming across Geocoordinate (https://docs.microsoft.com/en-us/dotnet/api/system.device.location.geocoordinate?redirectedfrom=MSDN&view=netframework-4.8). However I am not able to use the function GetDistanceTo.

Error :

"Geocordinate" does not contain a definition for "Getdistanceto" and was not can find no method of extension "Getdistanceto" that accept a first argument of the type "Geocoordinate"

Code c#:

using Nest;
using System;

namespace Gps
{
    class Program
    {
        static void Main(string[] args)
        {
            double long1 = -38.527498;
            double lat1 = -3.734876;
            double long2 = -38.529240;
            double lat2 = -3.743198;

            var locA = new GeoCoordinate(lat1, long1);
            var locB = new GeoCoordinate(lat2, long2);

            double distance = locA.GetDistanceTo(locB);
        }
    }
}

I think it must be bullshit, but I’ve already spent a lot of time trying to solve this problem, I thank you in advance if someone can help me pointing out where the mistake is.

  • 3

    What is this Nest? The fact that you didn’t using System.Device.Location may be the reason for the error. And may be confusing with this Nest.

  • @Maniero adding Nest was a recommendation from Visual Studio itself. I tried to remove it and add using System.Device.Location, as you advised, but I am unable to add a reference to System.Device.Location. Error : "Device" does not exist in the System namespace.

  • 1

    I’m pretty sure I got the problem right then. Now you need to resolve the issue of adding the reference I think has already been answered in https://answall.com/q/47598/101 or https://answall.com/q/47310/101 or https://answall.com/q/40761/101 or others.

1 answer

2


You have created a console solution that uses only the core of . NET Framework, which prevents you from adding references to assemblies because the purpose of this type of application is to be compatible with Mono.

When trying to use type GeoCoordinate in this type of application Intellisense informs the error and suggests installing the package Nest which has an incomplete version of the class GeoCoordinate.

To use the class GeoCoordinate first you have to create the right type project:

inserir a descrição da imagem aqui

The correct is the project in which it is written Console App(.NET Framework)

Created this project add the reference to Assembly System.Device, which is where Namespace is located System.Device.Location, and reference the namespace System.Device.Location in your code.

inserir a descrição da imagem aqui

Then your code will work smoothly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Device.Location;


namespace Gps
{
    class Program
    {
        static void Main(string[] args)
        {
            double long1 = -38.527498;
            double lat1 = -3.734876;
            double long2 = -38.529240;
            double lat2 = -3.743198;

            var locA = new GeoCoordinate(lat1, long1);
            var locB = new GeoCoordinate(lat2, long2);

            double distance = locA.GetDistanceTo(locB);
            Console.WriteLine("A distancia é:" + distance);
            Console.ReadLine();
        }
    }
}

inserir a descrição da imagem aqui

  • You could quote sources?

  • @Maurydeveloper: https://docs.microsoft.com/pt-br/dotnet/standard/choosing-core-framework-server. explains here the difference and the use cases of applications. NET Core and . NET Framework, the explanation is applied to server contexts but it is not difficult to extend knowledge to local console applications.

  • 1

    Good boy deserves +1. I understood everything.

  • @Maurydeveloper you saw, it seems, it was my impression, that the . NET Core is to be used in a similar way to Nodejs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.