Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert longitude and latitude string to double?

I'm getting my longitude and lattitude from google:

http://maps.google.com/maps/geo?q=Sliedrecht,%20Netherlands&output=csv&oe=utf8&sensor=false

I want to add a marker to my map using this results:

        if (coordinates.Length == 4 && coordinates[0] == "200")
        {
            var overlay = new GMapOverlay(mapexplr, "overlayTwo");

            overlay.Markers.Add(new GMapMarkerGoogleGreen(new PointLatLng(Convert.ToDouble(coordinates[2]), Convert.ToDouble(coordinates[3]))));
            mapexplr.Overlays.Add(overlay);
        }

The problem is that my marker is not displayed. I think it is because the doubles aren't provided in the correct format. The result of the above link is this:

200,4,51.8248681,4.7731624

When I convert the value 4.7731624 to a double I get 47731624, without the dot.

So my question is, how do I convert the string to a double with the dot in the right place?

like image 476
Martijn Avatar asked Dec 07 '25 08:12

Martijn


1 Answers

Chances are it's due to your culture - it sounds like in this case you want the invariant culture:

double longitude = double.Parse(text, CultureInfo.InvariantCulture);

(You may well want to use double.TryParse to gracefully handle the possibility of it not being a valid value.)

like image 153
Jon Skeet Avatar answered Dec 08 '25 22:12

Jon Skeet