Pregunta

I have passed a GeoPosition variable to a class and I need to convert it to type GeoCoordinate,but when I use the latitude and longtitude variables of type var it gives me an error that GeoCoordinate takes (double,double) parameters.

I understand that this means it has to take double parameters but how do I convert or cast the latitude and longtitude variables to be passed to its GeoCoordinate's constructor? Should I be converting using a different method?

if (NavigationContext.QueryString.ContainsKey("GeoLat") && NavigationContext.QueryString.ContainsKey("GeoLong"))
            {
              var latitude = NavigationContext.QueryString["GeoLat"];
              var longtitude = NavigationContext.QueryString["GeoLong"];
              var MyGeoPosition = new GeoCoordinate(latitude , longtitude ); 
            }
¿Fue útil?

Solución

From the MSDN documentation, it looks like NavigationContext.QueryString is an IDictionary<string, string>. This means that your two variables will be of type string.

Try casting your latitude and longitude variables to a type of double.

var latitude = Convert.ToDouble(NavigationContext.QueryString["GeoLat"]);
var longtitude = Convert.ToDouble(NavigationContext.QueryString["GeoLong"]);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top