Geocoding.net icon indicating copy to clipboard operation
Geocoding.net copied to clipboard

The Longitude Value does change when you get more then one GoogleGeocode.

Open georgioua opened this issue 10 years ago • 3 comments

The Longitude Value does change when you get more then one GoogleGeocode at a time.

georgioua avatar May 20 '15 04:05 georgioua

Could you provide some more detail of what you are sending and receiving and how the data differs from what you expect?

chadly avatar Jun 17 '15 02:06 chadly

I am just sending 2 address in Australia

foreach (string destination_address in destination_addresses) { IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "xxxxxx" };

            IEnumerable<Address> address = geocoder.Geocode(destination_address);

            if (address.Count() != 0)
            {
                addresses.Add(address.First());

                Console.WriteLine("Formatted: " + address.First().FormattedAddress); 
                Console.WriteLine("Coordinates: " + address.First().Coordinates.Latitude + ", " + addresses.First().Coordinates.Longitude); 
                //Console.ReadKey();
            }

            geocoder = null;
            address = null;


        }

georgioua avatar Jul 06 '15 07:07 georgioua

@georgioua You enumerate the IEnumerable 4 times in your loop. Thus, you call the Geocode function 4 times. I suppose you get more than one result and the result from System.Linq.First() delivers the other result on your second query, wether it is because Google returned them in another order or the Geocode function does something with the order.

Please provide the console output from this code: (change ApiKey & destinationAddress)

using (IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "xxxxxx" }){
    string destinationAddress = "###";
    Console.WriteLine("Query string: ", destinationAddress);
    for (int i=0; i<2; i++){
        Console.WriteLine("========");
        Console.WriteLine("Query #: ", i);
        Address[] address = geocoder.Geocode(destinationAddress).ToArray();
        for (int j=0; j < address.Length; j++){
            Console.WriteLine("Result #: " + j);
            Address a = address[j];
            Console.WriteLine("Formatted: " + a.FormattedAddress); 
            Console.WriteLine("Coordinates: " + a.Coordinates.Latitude + ", " + a.Coordinates.Longitude); 
        }
    }
}

0657code avatar Aug 07 '17 10:08 0657code