Is this a float.Parse bug?

I’m about to pull my hair out over this! What little I have, anyway.

I’ve got a script that is mostly working, thanks to everyone that has posted the bits that have helped me write this. I’ve seen lots of posts about getting XML feeds and not that many complete examples, so I’m going to post my whole code in case it helps anyone.

The code relies on TinyXMLReader from the wiki, so you must get that for it to work. You attach this to a game object and see the Console for the information from a saved Google Map RSS feed or you can just copy the RSS to your local drive and read it from there.

At any rate, my question is that I have got my longitude and latitude data in as floats but they are being rounded at least in the console, and then they are being seen as large numbers once applied to objects.

[Edit:] I just realized I had a script hard-coding a coordinate into the Prefab :sweat_smile:[/Edit]

At any rate, here’s some nice code to share :lol: The code below works.

Still having issues with rounding though: 39.731789 -104.960243 from GoogleMaps shows up in Unity as: 39.73179 -104.9602.

#pragma strict
#pragma implicit
#pragma downcast


var googleMapURL = "http://maps.google.com/maps/ms?hl=en&ie=UTF8&vps=1&jsv=277b&msa=0&output=georss&msid=111690159441157911175.00049077a794202865d17";
var useURL = false;

var vectors : Array = new Array();
var titles : Array = new Array();
var descriptions : Array = new Array();

var targetPrefab : Transform;


function Start()
{
	//Use this to read off the drive locally
	var xmlText = System.IO.File.ReadAllText(Application.dataPath + "/XML/fieldtest.xml");

	   
   //Use this to load a saved My Maps > Google Map
   if (useURL) {
	   	
	   	var www : WWW = new WWW (googleMapURL);
	
		// Wait for download to complete
		yield www;
		
		xmlText = [url]www.text;[/url]
  	}
    var reader = TinyXmlReader(xmlText);
    while (reader.Read())
    {
    	
//    	Show me all the XML fields that have been split from a Google Map RSS feed
//    	if(reader.isOpeningTag) {
//        	Debug.Log("Is an Opening Tag: " + reader.tagName + "\"" +  reader.content + "\"" + "\n");
//        }
 
        if(reader.isOpeningTag  reader.tagName == "title") {
        	var title : String[] = reader.content.Split("\n"[0]);

        	for (var t=0; t < title.length; t++){
        			titles.Push(title[t]);
        	}
        	
        	//Debug.Log("Title: " +  reader.content);
        }
        
         if(reader.isOpeningTag  reader.tagName == "![CDATA[<div") {
        	var description : String[] = reader.content.Split("\n"[0]);

        	for (var d=0; d < description.length; d++){
        			descriptions.Push(description[d]);
        	}
        	
        	//Debug.Log("Title: " +  reader.content);
        }
        
        
        if(reader.isOpeningTag  reader.tagName == "georss:point") {
        	
        	//Read all the coordinates
        	var Coords : String = reader.content;
        	
        	//Split the coordinates when we hit a space
        	Coordinates = Coords.Split(" "[0]);        	
			
			//Go through the splits and convert to Floats, then to a Vector3
			for (var v=0; v < Coordinates.length; v=v+2){
				
					//Could increase the change by trimming the incoming coordinates
//				    var trimmedlon = Coordinates[v].Substring(5,4);
//        			var trimmedlat = Coordinates[v+1].Substring(7,4);
				
				
					var longitude : float = float.Parse(Coordinates[v]);
					var latitude : float = float.Parse(Coordinates[v+1]);
					var geoLocation : Vector3 = new Vector3(longitude, 0.0, latitude);
	
        			vectors.Push(geoLocation);

        			
        	}
        }
        
    }
    
    //Drop the first value from the Title array
    titles.RemoveAt(0);
    yield WaitForSeconds(1);
    createTarget(titles.length);
    	
   	print("No. of Titles: " + titles.length + "\n" + "No. of Vectors: " + vectors.length + "\n"+"No. of Descriptions: " + descriptions.length + "\n");
   	
	print("Title: " + titles + "\n" + "Vectors: " + vectors + "\n" + "Descriptions: " + descriptions + "\n");


}

function createTarget(count : int){
	
	for (var x=0;x < count; x++) {
		
			var clone : Transform;
				
			clone = Instantiate(targetPrefab, vectors[x], Quaternion.identity);
			clone.transform.name = titles[x];
			
			Debug.Log("Title: " + titles[x] + "\n" + "Vectors: " + vectors[x] + " : " + "Descriptions: " + descriptions[x]  + " : " +  "Out Vector3: " +  "\n");

	}
	
}

That’s how Vector3s are formatted when output to the console using Debug.Log. The actual elements are not rounded. If you put

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

at the top of the Start function, you can leave out the Globalization stuff in the float.Parse statements. Not sure about the Instantiate problem.

–Eric