Database Reference
In-Depth Information
Listing 2.12
Translating location string into coordinates
public Location TranslateLoc(String loc) {
if(loc!=null&&!loc.isEmpty()) {
String encodedLoc= "" ;
try {
// Step 1: Encode the location name
encodedLoc = URLEncoder.encode(loc, "UTF-8" );
...
/ ** Step 2: Create a get request to MapQuest API with
the
* name of the location
* /
String url= "http://open.mapquestapi.com/nominatim/v1/
search?q=" +encodedLoc+ "&format=json" ;
String page = ReadHTML(url);
if(page!=null) {
try{
JSONArray results = new JSONArray(page);
if(results.length()>0) {
//Step 3: Read and extract the
coordinates of the location
as a JSONObject
Location loca = new Location(
results.getJSONObject(0).
getDouble( "lat" ),results.
getJSONObject(0).getDouble( "
lon" ));
return loca;
...
}
Source: Chapter2/location/LocationTranslationExample.java
to demonstrate this process. In Listing 2.12 , a summary of the method TranslateLoc
is provided, which is defined in the class LocationTranslateExample . The response
is provided in JSON, from which the coordinates can be easily extracted. If the
service is unable to find a match, it will return (0,0) as the coordinates.
2.7
Obtaining Data via Resellers
The rate limitations of Twitter APIs can be too restrictive for certain types of
applications. To satisfy such requirements, Twitter Firehose provides access to
100% of the public Tweets on Twitter at a price. Firehose data can be purchased
through third party resellers of Twitter data. At the time of writing of this topic,
there are three resellers of data, each of which provide different levels of access.
In addition to Twitter data some of them also provide data from other social media
platforms, which might be useful while building social media based systems. These
include the following:
 
Search WWH ::




Custom Search