Jan 18, 2012 at 6:49 PM
Edited Jan 18, 2012 at 6:50 PM
|
Hello all,
The code below is receiving information for turn by turn instructions but I am lacking the distance field in the JSON object. Am I missing a option to get this field. Otherwise the data is sorted by distance so I am not sure why I couldn't get
the distance value.
Thanks!
Dan
AsyncHttpClient client = new AsyncHttpClient();
private void pullTacoBellLocationsFromBing(double latitude, double longitude, double radius)
{
String requestStr = "http://api.bing.net/json.aspx?"
// Common request fields (required)
+ "AppId=" + "YourAppID"
+ "&Query=" + "LocationQuery"
+ "&Sources=Phonebook"
// Common request fields (optional)
+ "&Version=2.0"
+ "&Market=en-us"
+ "&UILanguage=en"
+ "&Latitude=" + latitude
+ "&Longitude=" + longitude
+ "&Radius=" + radius
+ "&Options=EnableHighlighting"
// Phonebook-specific request fields (optional)
+ "&Phonebook.Count=10"
+ "&Phonebook.Offset=0"
+ "&Phonebook.FileType=YP"
+ "&Phonebook.SortBy=Distance";
client.get(url, params, new JsonHttpResponseHandler() {
{
@Override
public void onSuccess(JSONObject json)
{
Vector<PlaceLocation> locations = new Vector<PlaceLocation>();
try
{
JSONObject SearchResponse = json.getJSONObject("SearchResponse");
JSONObject Phonebook = SearchResponse.getJSONObject("Phonebook");
JSONArray Results = Phonebook.getJSONArray("Results");
int ResultsLength = Results.length();
for (int i = 0; i < ResultsLength; i++)
{
JSONObject locationJson = Results.getJSONObject(i);
PlaceLocation location = new PlaceLocation(); //Object to hold data you need
location.type = TBLocation.Type.TACOBELL;
location.title = locationJson.getString("Title");
location.phone = locationJson.getString("PhoneNumber");
location.address = locationJson.getString("Address") + ' '
+ locationJson.getString("City") + ' '
+ locationJson.getString("StateOrProvince") + ' '
+ locationJson.getString("PostalCode");
location.latitude = locationJson.getDouble("Latitude");
location.longitude = locationJson.getDouble("Longitude");
locations.add(location);
}
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
listener.pullLocationsSucceeded(locations); //Your own listener implementation
}
});
}
|