- Home /
Yelp API- Latitude/Longitude parameter problem {Key/Value}
Hey guys, I have an issue that I can't quite figure out. Seems straightforward especially considering the script I compiled works smoothly. I collaborated and updated the yelp script that I posted on GitHub link text
Anyway, the yelp console indicates passing double values if I want to use latitude,longitude search method. For example, San Francisco's latitude/longitude is: 37.788022,-122.399797 . To pass this you'd have to use the "ll" key and then set the value like the example code indicates below{"ll",latitude_value,Longitude_value}:
public static string searchterm = "food";
public static string searchlocation = "San Francisco"+","+"Ca";
public static double latitude = 37.788022; //San Fran
public static double longitude = -122.399797;
public static string Coordinates = latitude + "," + longitude;
.......
// Fix up hashes to be webfriendly
searchLocation = Uri.EscapeDataString(searchLocation);
SortedDictionary<string, string> YelpParamsDictionary = new SortedDictionary<string, string> ()
{
{"term", searchterm },
// {"location",searchlocation }
{"ll", Coordinates } //<-------Here's the lat/long key/value paramter
};
WWW query = CreateYelpAPIQuery (YelpURL2,YelpParamsDictionary);
yield return query;
.......
........
Anyway, I recieved the JSON string when I use location method {"location","San Francisco"} with no problems. But when I switch to using their latitude/longitude method it gives me a bad request. No clue why. I have even tried converting the values to strings. Here's yelps api console - link text
Answer by Bunny83 · Nov 14, 2015 at 04:44 AM
Just a shot in the dark: What's your nationality? Because some countries use a comma as decimal point. Since double/float to string conversion uses the systems culture settings your lat long string might look like this:
"37,788022,-122,399797"
instead of
"37.788022,-122.399797"
Of course that format most likely isn't recognised. You should make sure to use a culture neutral conversion. Using the Invariant culture is usually the best approach when converting numbers to string.
If that's not the problem, make sure your Decimal Degrees lat / lon format is actually accepted by the site. There are a lot of different ways you can write down lat/lon coordinates.
edit
Ok. Since you took that example from the API documentation they should accept decimal Degrees ^^. So it's probably the to string conversion. You can check this easily be printing out all your parameters before you make that request.
Answer by OJ3D · Nov 15, 2015 at 09:57 AM
Bunny83 - thanks for getting back to me. I really appreciate it. I tried your method, and unfortunately didn't get any traction.
public static string latitude = "38.882071"; //washington dc
public static string longitude = "-77.111845";
public static string Coordinates = latitude.ToString (CultureInfo.CreateSpecificCulture ("de-DE")) + "," + longitude.ToString (CultureInfo.CreateSpecificCulture ("de-DE"));
//Coordinates = 38,882071,-77,111845
{"ll", Coordinates} //gives me errors
I Got similar errors. :(. FYI-I'm american,from DC. I don't get why the parameter is being so sensitive, I'm completely baffled. I moved to using the zip code method until it can get figured out- that key/value pair is:
public static string zipcode= "22209";
{"location",zipcode}
I get a response back,which is good. This kind of get's me there, but the center/reference point of a zip code can be totally different from a specific location(zip-lat/long vs. a specific location-lat/long). A zipcode is area-based which means it could cover a a lot of ground or not.