summaryrefslogtreecommitdiff
path: root/src/com/lc8n/android/LCGoogleSearch.java
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2010-10-29 00:48:14 +0100
committerJoe Robinson <joe@lc8n.com>2010-10-29 00:48:14 +0100
commit6093815099eb6d6c3d978579ccbdde38fa916f13 (patch)
treed99bd4e993b0e0ffd96dc1be8863512060681b6e /src/com/lc8n/android/LCGoogleSearch.java
Untouched work since submission for university project 04/05/2010. Messy code, a bit glitchy.HEADmaster
Diffstat (limited to 'src/com/lc8n/android/LCGoogleSearch.java')
-rw-r--r--src/com/lc8n/android/LCGoogleSearch.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/com/lc8n/android/LCGoogleSearch.java b/src/com/lc8n/android/LCGoogleSearch.java
new file mode 100644
index 0000000..a0b207c
--- /dev/null
+++ b/src/com/lc8n/android/LCGoogleSearch.java
@@ -0,0 +1,86 @@
+package com.lc8n.android;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+
+public class LCGoogleSearch {
+
+ public InputStream getJSONData(String url){
+
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ URI uri;
+ InputStream data = null;
+ try{
+ uri = new URI(url);
+
+
+ HttpGet method = new HttpGet(uri);
+ method.addHeader("Referer", "http://www.lc8n.co.uk");
+ HttpResponse response = httpClient.execute(method);
+ data = response.getEntity().getContent();
+
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+
+
+ return data;
+
+ }
+
+ public List<Result> runJSONParser(String request, double lat, double lng, double latspan, double lngspan, String db){
+
+ String url = "http://lc8n.co.uk/search.php?q="+request;
+
+ if(db.equals("Google Maps"))
+ {
+ url = "http://ajax.googleapis.com/ajax/services/search/local?v=3.0&q="+request+"&sll="+lat+","+lng+"&sspn="+latspan+","+lngspan+"&rsz=large"
+ +"&key=ABQIAAAAdosJ9FP7ajF_9f3Z_cbYoRSy5sbAFFtUu9frF3oeYhqN3FjpixTyLH_nlb9PV1c3EJNEVLBTLfI7JQ&sensor=true";
+ }
+
+ List<Result> results = Collections.emptyList();
+ Reader r = new InputStreamReader(getJSONData(url));
+// Reader r = new InputStreamReader(getJSONData("http://ajax.googleapis.com/ajax/services/search/local?v=3.0&q="+request+"&sll="+lat+","+lng+"&sspn="+latspan+","+lngspan+"&rsz=large"
+// +"&key=ABQIAAAAdosJ9FP7ajF_9f3Z_cbYoRSy5sbAFFtUu9frF3oeYhqN3FjpixTyLH_nlb9PV1c3EJNEVLBTLfI7JQ&sensor=true"));
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ ResponseData responseData = mapper.readValue(r, ResponseData.class);
+ System.out.println(responseData.getResponseData().getResults());
+ Results result = responseData.getResponseData();
+ results = result.getResults();
+
+
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return results;
+
+
+ }
+
+}