Question

I am working in c#.Net. My requirement is to get the latitude and longitude from the api, based on the address,city,state and zip which had given as a parameter.

I am having 350 stores details in a excel sheet. Initially i had used google api.

if (strAdd != "" && strCity != "" && strState != "" && strZip != "" && strStoreNo != "")
                {
                    Address = strAdd.Trim() + "," + strCity.Trim() + "," + strState.Trim() + "," + strZip.Trim();
                    string routeReqUrl = "http://maps.google.com/maps/geo?q={0}&output=xml&oe=utf8&sensor=true_or_false&key={1}";
                    string url = string.Format(routeReqUrl, Address.Replace(' ', '+'), "ABQIAAAA5rV-auhZekuhPKBTkuTC3hSAmVUytQSqQDODadyYeWY4ZYaVyRRv4thyrzzOQ7AMUl_hIjoG8LomGA");
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                    req.Method = "GET";
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    Stream respStream = resp.GetResponseStream();
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(respStream);
                    if (xDoc.GetElementsByTagName("coordinates")[0].InnerText.Contains(","))
                    {
                        string[] coordinates = xDoc.GetElementsByTagName("coordinates")[0].InnerText.Split(',');
                        string Latitude = coordinates[1];
                        string Longtitude = coordinates[0];

                        Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
                    }
                }

In the above code, only around for 10 to 15 stores i can able to get the latitude and longitude details. After that i am getting the object reference error in "(xDoc.GetElementsByTagName("coordinates")[0].......".

After that i had tried with yahoo api, i am using the same excel sheet which had 350 stores.

dsxml.ReadXml("http://where.yahooapis.com/geocode?appid=capelinks&location=" + Address + "&Geocode=Geocode");
                    if (dsxml.Tables[0].Rows.Count > 0)
                    {
                        if (dsxml.Tables[1].TableName == "Result")
                        {
                            string Latitude = dsxml.Tables[1].Rows[0]["Latitude"].ToString();
                            string Longtitude = dsxml.Tables[1].Rows[0]["Longitude"].ToString();
                            Logger.Log.Debug("[Latitude and Longitude] " + " Store - No " + strStoreNo + " Addr Line 1 " + strAdd + " Latitude " + Latitude + " Longitude " + Longtitude);
                        }
                    }

Here, its process all the 350 stores correctly without any error.

What will be the issue with google api. whether there are any restrictions for taking the latitude and longitude details for large number of stores.

Was it helpful?

Solution

I'm not sure if this is your example problem, but the Google Geocoding API V2 docs mention that the V2 version is deprecated now:

Note: The Google Maps Geocoding API Version 2 has been officially deprecated as of March 8, 2010. The V2 API will continue to work until Mar 8, 2013. We encourage you to migrate your code to the new Geocoding API.

You could try switching to the latest Geocoding API V3. One thing to keep in mind is Google terms mention only allowing this service when you are displaying results in the context of a Google Map.

If the Yahoo service is providing the data you need, I would stick with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top