Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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 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.
Posted
Updated 14-Oct-14 0:16am
v2

1 solution

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[^]
 
Share this answer
 
Comments
CPallini 14-Oct-14 6:23am    
5.
christhuxavier 14-Oct-14 6:46am    
okay. the one you put url that belongs to windows.

i am developing project using asp.net web app. how to get latitude and longitude of location
Pheonyx 14-Oct-14 6:58am    
Although this is for MVC, I believe you could use a similar approach with standard ASP.Net but in essence you need some client side Javascript to post the geolocation data back to the server:

Sample Link
For other options try Here
christhuxavier 14-Oct-14 8:45am    
yes. i used JavaScript function which returns longitude and latitude. when i test in google map with those longitude and latitude, it shows wrong place.

if you look at android, just they use "LocationManager" class. they did not pass any address or pincode. But it returns longitude and latitude after they create object for location manager. likewise MSDN has System.Device.Location namespace. But i do not know to get longitude and latitude of my device located.
RaisKazi 14-Oct-14 10:21am    
My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900