First Android app: Earthquake

Today I will remake the example application in the book by Reto Meier Professional Android 2 Application Development published by Wrox. (ISBN: 978-0-470-56552-0)

Indeed since the USGS revised its information flows, the application crashes at start becoming useless. And as I liked having information on earthquakes, i’ll do the update. Moreover, this is an opportunity to work with the OpenStreetMap API for Android.

Install the work environment

My first task was to download an appropriate development environment: Android Studio .

I moved and I spear. Whoops! An error message …

Error launching Android Studio

Ok, obviously it isn’t know the PATH until my JDK.
I reinstall the java Jdk in its latest version.

But it still crashes with the same error message. Fortunately Stackoverflow gives me the answer. In fact we must add two paths in the environment variables:

      • JAVA_HOME: the path to the root of the JDK
      • PATH: the path to the bin directory of the JDK
JAVA_HOME C:/Program Files/Java/jdk1.7.0_40/jre
PATH C:/Program Files/Java/jdk1.7.0_40/jre/bin 

We restart the Android Studio.

Android Studio

A nice loader screen: everytghing is ok.

I create a new project: File> New Project.

I filled out the necessary information for my project.

Nouveau projet 1 / 4 Nouveau projet 2 / 4 Nouveau projet 3 / 4 Nouveau projet 4 / 4

And it creates an initial files tree, compile newly created files
Building gradle
and shows us a Hello World in a pretty Nexus 4.
Environnement de développement

Working with Open Street Map

I will use osmdroid ( ) that displays a map using OpenStreetMap tiles ( http:/ / ). It can be used free and without application-specific key, unlike Google Map ( ).

So I downloaded the Jar of osmdroid and that of SLF4J Android which osmdroid depends on.

and I copy these two jar with windows explorer in a libs folder created in Earthquake folder of my project, next to src and build .


Then in Android Studio, I’ll include these two libraries.
In the project tree, I select the two items and right-click menu shows me the following:

I chose Add as library .

Now I can edit the file src/main/res/layout/activity_main.xml.
I delete the default Hello World and I put a Mapview instead:

   android: id = "@id/mapview"
   android: layout_width="match_parent"
   android: layout_height="match_parent"

You should also add this to the src/main/AndroidManifest.xml file for the application to load the Mapview and the Mapview to work.

<uses-library android:name="org.osmdroid.views.MapView" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Then i edit the file with this code:

ch.moutons.earthquake package;
import android.os.Bundle;
import org.osmdroid.views.MapView;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.ResourceProxy;
import org.osmdroid.DefaultResourceProxyImpl;
public class extends Activity {MainActivity
MapView map;
protected void onCreate (Bundle savedInstanceState) {
   super.onCreate (savedInstanceState);
   setContentView (R.layout.activity_main);
   map = (MapView) findViewById (;
   map.setTileSource (TileSourceFactory.DEFAULT_TILE_SOURCE);
   GeoPoint startPoint = new GeoPoint (52370816, 9735936);
   MapController mapController map.getController = ();
   mapController.setCenter (startPoint);
   map.setBuiltInZoomControls (true);
   mapController.setZoom (2);
   map.setUseSafeCanvas (true);
   map.setUseDataConnection (true);

I make a test by pressing the Run button run to start the compilation and test it in the debugger.
Premier essai
We see that the application is loaded and the zoom works but osmdroid does not display the images of the map. This may be due to the debugger. Actually exporting the application on my phone displays the map perfectly.

2013-10-06 12.13.16

Ok, it rolls

Geographic Coordinates

I now write a class to search the geographical coordinates of the epicenters of earthquakes.

The USGS (United States Geological Survey – ) publishes on its website information on the latest earthquakes recorded: http://earthquake.usgs .gov/earthquakes/feed/v1.0 /.

I utiliseGeojson ( ) to decode the JSON feed from the USGS once coordinates collected in a Hashtable, you can display them on the map.

Click on a point to display a Toast

AND finally, I get this gorgeous map with earthquakes.

2013-10-08 09.11.20

Download the apk file: earthquake.apk (808Ko)
Download the source code of the application: EarthquakeProjectzip (6MB)

Posted in Non classé

Google Maps

I revised my interactive maps to upgrade to version 3 of the Google Map API.

You will find:

Posted in Non classé

Search on Twitter

Twitter has recently launched a subdomain dedicated to the search for tweets.

The most interesting is undoubtedly the Advanced Search which allows searching:

  • people with operators from: and to:
  • .

  • by geographic location with operator near and within:
  • .

  • by time period since: YYYY-MM-DD and until:. YYYY-MM-DD
  • by attitude when using smileys 🙂 and: (and the question ()
  • ?

  • by the presence of links filter: links or retweets include: retweets

It is possible to filter tweets to discover new things or to inform .

Posted in Non classé

The center of Google Map

To find the coords of the center of a Google Map, just type this javascript in the address bar of the browser:

Posted in Non classé