How to convert longitude and latitude string to double?
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.)
Martijn
Updated on June 14, 2022Comments
-
Martijn almost 2 years
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 get47731624
, without the dot.So my question is, how do I convert the string to a double with the dot in the right place?