我正在获得经度和纬度是NaN [英] I am getting longitude and latitude is NaN

查看:175
本文介绍了我正在获得经度和纬度是NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Device.Location;

namespace GPSlonandlat
{
    public static class GeoLocation
    {
        public static double geoloclon { get; set; }
        public static double geoloclat {get;set;}
  
        static GeoLocation()
        {
            GeoCoordinate coordinate = new GeoCoordinate();
            geoloclon = coordinate.Longitude;
            geoloclat = coordinate.Latitude;
        }
    }
}





geoloclon和geoloclat获得'NaN'..我正在获得空的..



注意:我在本地主机上运行这个项目。也许如果我在本地主机上运行,​​我将获得经度和空位。



geoloclon and geoloclat gets 'NaN'.. i am getting empty..

Note: i am running this project in local host. may be if i run in local host, i will be getting longitude and latitude to be empty.

推荐答案

你根本就没有找到你的GeoCoordinate。

MSDN - system .device.location.geocoordinate [ ^ ]

如果查看GeoCoordinate类的文档(上面的链接),那么你可以在默认构造函数旁边看到它的状态初始化没有设置数据字段的GeoCoordinate的新实例。这就是你获得NaN值的原因。


这是获取设备位置的一些MSDN示例代码的链接:

< a href =https://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66> https://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66 [ ^ ]
You aren't finding your GeoCoordinate by doing that at all.
MSDN - system.device.location.geocoordinate[^]
If you look at the documentation on the GeoCoordinate class (link above) then you can see it states next to the default constructor "Initializes a new instance of GeoCoordinate that has no data fields set." This is why you are getting NaN values back.

This is a link to some MSDN example code for getting a devices location:
https://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66[^]


这篇关于我正在获得经度和纬度是NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆