Jump to content

4 posts in this topic

Posted

So when I try to retrieve the full gps coordinates from my class I get the correct values. When I am looking at the debugger it shows the xml document contains the right values. However when I call float myVar = locationElem.Element("lat") or float myVar = float.Parse(locationElem.Element("lat").Value); it trims the value short. How do I force it to return the absolute float in the document?

Share this post


Link to post
Share on other sites

Posted

To clarify:
[code]

string status = xDoc.Element("GeocodeResponse").Element("status").Value;
XElement locationElem = xDoc.Element("GeocodeResponse").Element("result").Element("geometry").Element("location");
double testLat = (double)locationElem.Element("lat");
double testLong = (double)locationElem.Element("lng");
float latitude = (float)float.Parse(locationElem.Element("lat").Value);
float longitude = (float)float.Parse(locationElem.Element("lng").Value);
[/code]
locationElem.Value (for example) = 22.01919203 but the float is stored as 22.0191...o_O? What can I do to get the full 22.0191203?

Share this post


Link to post
Share on other sites

Posted

That's probably because floats don't have enough precision to store that many significant decimal places. You should use a [url="http://msdn.microsoft.com/en-us/library/vstudio/system.decimal.aspx"]decimal[/url] instead. Btw you should always specify CultureInfo.InvariantCulture to those Parse methods otherwise they will fail on any machine that has a different decimal separator.
1 person likes this

Share this post


Link to post
Share on other sites

Posted

Thanks Dr_Asik :) helpful as always. +1 for you (I think there is an up vote button on here? I'll find it :) ).
EDIT: There isn't one for an individual post so I rated you 5 stars on your profile. I was banging my head on my desk about this one. Google even shows an example using floats so I was a bit confused as to why my example wasn't working like theirs was. I'm going to try the decimal idea though. Lets hope for the best!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.