Hi!

First, Google Local Search return the results in JSON format.
This is an example link :
http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=Restaurant,%20loc:%2047.3,8.6&hl=en&rsz=large&start=1

I create my url using latitude and longitude got from GPS like this:
String url = "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=";
+ what + ",%20loc:%20" + lat +"," + lng + "&hl=en&rsz=large&start=" +
offset;

here is my JSON Parser class:

package com.liviu.app.nearbyplace.data;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.liviu.app.nearbyplace.util.Util;

public class JSONParser {
 // data
private String TAG = "JSONParser";
private ArrayList<ItemFound> items;
private ItemFound itemFound;
 public JSONParser() {
items = new ArrayList<ItemFound>();
}
 public boolean parse(String source){
String result  = Util.getFile(source);
if(result.length() < 1)
return false;
Log.e(TAG, "parse " + result);
items.clear();
 try {
JSONObject json = new JSONObject(result);
JSONObject jsec = json.getJSONObject("responseData");
JSONArray jResults = jsec.getJSONArray("results");
jResults.toString();
for(int i = 0; i < jResults.length(); i++){
JSONObject jObj = jResults.getJSONObject(i);
itemFound = new ItemFound();
itemFound.setTitle(jObj.getString("title"));
itemFound.setCity(jObj.getString("city"));
itemFound.setCountry(jObj.getString("country"));
itemFound.setContent(jObj.getString("content"));
 JSONArray phoneObj = jObj.getJSONArray("phoneNumbers");
for(int j = 0; j < phoneObj.length(); j++){
JSONObject jPhoneObj = phoneObj.getJSONObject(j);
if(jPhoneObj.getString("type").length() < 1)
itemFound.setPhone(jPhoneObj.getString("number"));
else if(jPhoneObj.getString("type").equals("Fax"))
itemFound.setFax(jPhoneObj.getString("number"));
}
itemFound.setLatitude(jObj.getString("lat"));
itemFound.setLongitude(jObj.getString("lng"));
itemFound.setStreet(jObj.getString("streetAddress"));
Log.e(TAG, "ItemFound: " + itemFound.toString());
items.add(itemFound);
}
 Log.e(TAG, "parse() finished with " + items.size() + " items found!");
}
catch (JSONException e) {
e.printStackTrace();
return false;
}
 return true;
}
 public ArrayList<ItemFound> getItemsFound() {
return items;
}

}


Hope this helps!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to