SlideShare a Scribd company logo
Average
An android aplication



                        Manuela Alvarez
                             Ipsit Dash
Outline
• Environment

• Open Street Maps

• Our aplication

• Code

• Running the aplication

• What’s next?

• Video demostration
Environment
 Eclipse IDE for Java Developers
 Android SDK Tools
 Apache Tomcat
 PostgresSQL OpenSource Database
Open Street Maps
• Lot of possibilities

• Multiple Web tools: ITO OSM tools, OSM
  inspector, OpenStreetBugs, Mapnik,
  Cloudmade, OpenCycleMap, OpenBusMap

• Android: Mapzen POI Collector (Uses
  Cloudmade), Osmand (OSM Automated
  Navigation Directions)
Our Aplication
Our aplication allows users getting the average position of a set
of points




        Current point                   Average point
General view of the code
Android Aplication                    Dynamic Web                      Database
  Main_Activity                         DynWeb

OnlocationChanged           Servlet    Location Connect
                                                                        postgres
                            (Hub)               database
OnCreate                                        (ConnDB)
DisplayLabel
OnDraw

  Layout              OnlocationChanged: Starts when change in location
  Activity_main.xml   OnCreate: Sets the display of OSM and Label
                      DisplayLabel: Says what to show in the label
                      OnDraw: Draws the points
                      Servlet: Sets request and response between device and database
                      Location: Starts when location is changed
                                Looks what the new position is
                                Sends position to the database where it is run SQL query
     Emulator                   Get reponse from database
                      ConnDB: Connects server to database
Code                                        Set request and response



Dynamic Web. Servlet
...
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// TODO Auto-generated method stub
String point = request.getParameter("point");
          if("location".equalsIgnoreCase(point)) {
          Location location = new Location();
          Location.getLocation(request, response);
         }
}
...
                                                         Connects server and database
Dynamic Web. Conection to database
...
private Connection connection = null;
public Connection getConn() {
Class.forName("org.postgresql.Driver").newInstance();
String url = "jdbc:postgresql://localhost:5432/postgres" ;
connection = DriverManager.getConnection(url, "postgres" , "postgres" );
}
...
Code
                                            Telling the database
                                            how to store the records
Dynamic Web. Location
...
ConnDB conndb = new ConnDB();
String updateSQL = "insert into allPositions(reportlat, reportlon) select " + lat + ", " + lon;
connect = conndb.getConn();
Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(updateSQL);


Statement stmt2 = connect.createStatement();
stmt2.executeQuery("select avg(reportlat) avgreportlat,avg(reportlon) avgreportlon from allPositions");
ResultSet rs = stmt2.getResultSet();
rs.next();
double avglon = rs.getDouble(1);
double avglat = rs.getDouble(2);
DataOutputStream dos = new DataOutputStream(response.getOutputStream());
dos.writeUTF("Succeed:" + avglon + ":" + avglat);

...


                     Sending a SQL query to get back the average of all latitude
                     and longitude values that are already store in the database
Code                                                           Displaying map

Main_Activity. OnCreate
public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        mapView = (MapView) this.findViewById(R.id.mapview);
        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);
        mapController = mapView.getController();                                     GPS
        mapController.setZoom(11);
        point = new GeoPoint(59351756, 18057822);
        mapController.setCenter(point);

        mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*1000, 10,locListener);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);                            Setting zoom
        Label = (TextView)findViewById(R.id.Label);
   }



                               Label to show average point coordinates
Code
Main_Activity. OnLocationChanged
...                                                                           Connect to the server
url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("Charest", "utf-8");
urlConn.connect();                                                           Sending latitude and
DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());      longitude from current
dop.writeBytes("point=" + URLEncoder.encode("location","utf-8"));
dop.writeBytes("&lon=" + URLEncoder.encode(Double.toString(Lon),"utf-8"));   positionto the server
dop.writeBytes("&lat=" + URLEncoder.encode(Double.toString(Lat),"utf-8"));
dop.flush();
dop.close();

DataInputStream dis = new DataInputStream(urlConn.getInputStream());
String locPassage = dis.readUTF();
String[] mystrings = locPassage.split(":");
AVGLat = Double.parseDouble(mystrings[1]);                       Reading latitude and longitude
AVGLon = Double.parseDouble(mystrings[2]);
noavgyet = false;
                                                                 of the average point of all
                                                                 recorded points and display
displayLabel(locPassage);
...                                                              it in the label
Code                                                            Setting the OSM display
Main_Activity. Activiy_main.xml
...
           <org.osmdroid.views.MapView
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@+id/mapview"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:clickable="true" />                                  Setting the label
      <TextView
          android:id="@+id/Label"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_margin="5dip"
          android:text="Welcome!"
      />
...                                                          Drawing the average point
Main_Activity .OnDraw
...
if (!noavgyet) {
          GeoPoint pointavg = new GeoPoint((int)(AVGLat*1e6), (int)(AVGLon*1e6));
          Paint paint2 = new Paint();
          paint2.setColor(Color.GREEN);
          Point screenPoint2 = new Point();
          mapView.getProjection().toPixels(pointavg, screenPoint2);
          Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.dot2);
          canvas.drawBitmap(bmp2, screenPoint2.x, screenPoint2.y, paint2);
...
Running the aplication
Simulate GPS with Dalvik Debug Monitor Server
KML file with 5 points in Vaxholm




                     -- Table: allpositions
Database
                     -- DROP TABLE allpositions;

                     CREATE TABLE allpositions
Allpositions table   (
With 2 columns:        reportlat double precision,
                       reportlon double precision
reportlat            )
reportlon            WITH (
                       OIDS=FALSE
                     );
                     ALTER TABLE allpositions OWNER TO postgres;
Running the aplication
                         Current point


                         Average point
Use of the app
Imagine you want to build a factory in a city with a certain number of houses

Assume that we know where future workers live

Collect the coordinates from their houses positions

Get average position coordinates

This minimizes the total travelling distance from workers houses to the factory
What’s next
•   Add a reset button to clear records from the database
•   Add a button for getting GPS coordinates when pushed
•   Sharing location between users
•   Drawing all recorded points in the display
Thank you!




             Video demostration

More Related Content

What's hot (20)

PDF
G*ワークショップ in 仙台 Grails(とことん)入門
Tsuyoshi Yamamoto
 
PDF
Aplicações assíncronas no Android com
Coroutines & Jetpack
Nelson Glauber Leal
 
PDF
State managment in a world of hooks
500Tech
 
PDF
Demoiselle Spatial Latinoware 2011
Rafael Soto
 
PPTX
Android Developer Toolbox 2017
Shem Magnezi
 
PDF
The Ring programming language version 1.9 book - Part 71 of 210
Mahmoud Samir Fayed
 
PDF
Do you know what your drupal is doing? Observe it!
Luca Lusso
 
PDF
Building android apps with kotlin
Shem Magnezi
 
PPTX
097 smart devices-con_las_aplicaciones_de_gestión
GeneXus
 
PPTX
Cnam azure 2014 mobile services
Aymeric Weinbach
 
PDF
Arquitetando seu aplicativo Android com Jetpack
Nelson Glauber Leal
 
PPTX
Entity Framework Core & Micro-Orms with Asp.Net Core
Stephane Belkheraz
 
PDF
Bangun datar dan bangun ruang
SanSan Yagyoo
 
PPTX
Hadoop gets Groovy
Steve Loughran
 
PDF
The Ring programming language version 1.10 book - Part 79 of 212
Mahmoud Samir Fayed
 
PDF
rx.js make async programming simpler
Alexander Mostovenko
 
PDF
Introdução ao Desenvolvimento Android com Kotlin
Nelson Glauber Leal
 
PDF
Knock, knock, who is there? Doze.
Yonatan Levin
 
PDF
Visual Studio.Net - Sql Server
Darwin Durand
 
PDF
Mastering Kotlin Standard Library
Nelson Glauber Leal
 
G*ワークショップ in 仙台 Grails(とことん)入門
Tsuyoshi Yamamoto
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Nelson Glauber Leal
 
State managment in a world of hooks
500Tech
 
Demoiselle Spatial Latinoware 2011
Rafael Soto
 
Android Developer Toolbox 2017
Shem Magnezi
 
The Ring programming language version 1.9 book - Part 71 of 210
Mahmoud Samir Fayed
 
Do you know what your drupal is doing? Observe it!
Luca Lusso
 
Building android apps with kotlin
Shem Magnezi
 
097 smart devices-con_las_aplicaciones_de_gestión
GeneXus
 
Cnam azure 2014 mobile services
Aymeric Weinbach
 
Arquitetando seu aplicativo Android com Jetpack
Nelson Glauber Leal
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Stephane Belkheraz
 
Bangun datar dan bangun ruang
SanSan Yagyoo
 
Hadoop gets Groovy
Steve Loughran
 
The Ring programming language version 1.10 book - Part 79 of 212
Mahmoud Samir Fayed
 
rx.js make async programming simpler
Alexander Mostovenko
 
Introdução ao Desenvolvimento Android com Kotlin
Nelson Glauber Leal
 
Knock, knock, who is there? Doze.
Yonatan Levin
 
Visual Studio.Net - Sql Server
Darwin Durand
 
Mastering Kotlin Standard Library
Nelson Glauber Leal
 

Viewers also liked (20)

PDF
Positioning the Solitaire
Hydrographic Society Benelux
 
PDF
Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Hydrographic Society Benelux
 
PDF
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Zaw Aung
 
PDF
Advance presentation patras
Yannis Koliousis
 
PDF
Whalsay Slides
James Titcomb
 
DOC
CV.June 2015
Capt. Victor Tambelangi
 
PPT
Positioning challenges on fallpipe vessels
Hydrographic Society Benelux
 
PDF
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Andrew Neville
 
PDF
GPS Status en Evolutie
Hydrographic Society Benelux
 
PPTX
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...
James Titcomb
 
PPTX
Dark diamond
Ipsit Dash
 
PDF
Opportunities for the Hydrographic Sector Using Satellite Observation Services
Hydrographic Society Benelux
 
PDF
E Mar Piraeus Presentation Welcome Address by Jenny Rainbird
Yannis Koliousis
 
PDF
De eerste GLONASS-K Satellieten en de CDMA formaten
Hydrographic Society Benelux
 
PPTX
Drones, een overzicht
Hydrographic Society Benelux
 
PPTX
Konsberg K-DP Guide
Capt. Victor Tambelangi
 
PPTX
Work Ethics
Fercygim Bunoan
 
PDF
Enabling RTK-like positioning offshore using the global VERIPOS GNSS network
Hydrographic Society Benelux
 
ODP
20161102 agmjht
James Titcomb
 
PDF
Gravity Expeditions at Sea
Hydrographic Society Benelux
 
Positioning the Solitaire
Hydrographic Society Benelux
 
Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Hydrographic Society Benelux
 
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Zaw Aung
 
Advance presentation patras
Yannis Koliousis
 
Whalsay Slides
James Titcomb
 
Positioning challenges on fallpipe vessels
Hydrographic Society Benelux
 
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Andrew Neville
 
GPS Status en Evolutie
Hydrographic Society Benelux
 
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...
James Titcomb
 
Dark diamond
Ipsit Dash
 
Opportunities for the Hydrographic Sector Using Satellite Observation Services
Hydrographic Society Benelux
 
E Mar Piraeus Presentation Welcome Address by Jenny Rainbird
Yannis Koliousis
 
De eerste GLONASS-K Satellieten en de CDMA formaten
Hydrographic Society Benelux
 
Drones, een overzicht
Hydrographic Society Benelux
 
Konsberg K-DP Guide
Capt. Victor Tambelangi
 
Work Ethics
Fercygim Bunoan
 
Enabling RTK-like positioning offshore using the global VERIPOS GNSS network
Hydrographic Society Benelux
 
20161102 agmjht
James Titcomb
 
Gravity Expeditions at Sea
Hydrographic Society Benelux
 
Ad

Similar to Average- An android project (20)

PDF
Mobile Web 5.0
Michael Galpin
 
PPTX
What's New in Android
Robert Cooper
 
PDF
Workshop 25: React Native - Components
Visual Engineering
 
PPT
Mobile webapplication development
Ganesh Gembali
 
PDF
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
PDF
mobl
zefhemel
 
PPTX
Hazelcast and MongoDB at Cloud CMS
uzquiano
 
PDF
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Codemotion
 
PDF
How to use geolocation in react native apps
InnovationM
 
PDF
What's the deal with Android maps?
Chuck Greb
 
PPTX
SharePoint Conference 2018 - APIs, APIs everywhere!
Sébastien Levert
 
KEY
CouchDB on Android
Sven Haiges
 
PDF
Building cross-platform mobile apps with React Native (Jfokus 2017)
Maarten Mulders
 
PPTX
Android 3
Robert Cooper
 
PDF
Webgl para JavaScripters
gerbille
 
PDF
Crossing platforms with JavaScript & React
Robert DeLuca
 
PPT
Android Support Library
Alexey Ustenko
 
PPTX
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
PDF
maXbox Starter 39 GEO Maps Tutorial
Max Kleiner
 
PDF
Connect.js - Exploring React.Native
joshcjensen
 
Mobile Web 5.0
Michael Galpin
 
What's New in Android
Robert Cooper
 
Workshop 25: React Native - Components
Visual Engineering
 
Mobile webapplication development
Ganesh Gembali
 
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
mobl
zefhemel
 
Hazelcast and MongoDB at Cloud CMS
uzquiano
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Codemotion
 
How to use geolocation in react native apps
InnovationM
 
What's the deal with Android maps?
Chuck Greb
 
SharePoint Conference 2018 - APIs, APIs everywhere!
Sébastien Levert
 
CouchDB on Android
Sven Haiges
 
Building cross-platform mobile apps with React Native (Jfokus 2017)
Maarten Mulders
 
Android 3
Robert Cooper
 
Webgl para JavaScripters
gerbille
 
Crossing platforms with JavaScript & React
Robert DeLuca
 
Android Support Library
Alexey Ustenko
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
maXbox Starter 39 GEO Maps Tutorial
Max Kleiner
 
Connect.js - Exploring React.Native
joshcjensen
 
Ad

More from Ipsit Dash (6)

PPTX
Land Reforms : An overview
Ipsit Dash
 
PPTX
Water Sector Debate
Ipsit Dash
 
PPTX
Tirupur Water Supply and Sanitation
Ipsit Dash
 
PPTX
Spatial Data Mining : Seminar
Ipsit Dash
 
PPTX
Change Detection Dubai
Ipsit Dash
 
PPTX
Implementation of INS-GPS
Ipsit Dash
 
Land Reforms : An overview
Ipsit Dash
 
Water Sector Debate
Ipsit Dash
 
Tirupur Water Supply and Sanitation
Ipsit Dash
 
Spatial Data Mining : Seminar
Ipsit Dash
 
Change Detection Dubai
Ipsit Dash
 
Implementation of INS-GPS
Ipsit Dash
 

Average- An android project

  • 1. Average An android aplication Manuela Alvarez Ipsit Dash
  • 2. Outline • Environment • Open Street Maps • Our aplication • Code • Running the aplication • What’s next? • Video demostration
  • 3. Environment Eclipse IDE for Java Developers Android SDK Tools Apache Tomcat PostgresSQL OpenSource Database
  • 4. Open Street Maps • Lot of possibilities • Multiple Web tools: ITO OSM tools, OSM inspector, OpenStreetBugs, Mapnik, Cloudmade, OpenCycleMap, OpenBusMap • Android: Mapzen POI Collector (Uses Cloudmade), Osmand (OSM Automated Navigation Directions)
  • 5. Our Aplication Our aplication allows users getting the average position of a set of points Current point Average point
  • 6. General view of the code Android Aplication Dynamic Web Database Main_Activity DynWeb OnlocationChanged Servlet Location Connect postgres (Hub) database OnCreate (ConnDB) DisplayLabel OnDraw Layout OnlocationChanged: Starts when change in location Activity_main.xml OnCreate: Sets the display of OSM and Label DisplayLabel: Says what to show in the label OnDraw: Draws the points Servlet: Sets request and response between device and database Location: Starts when location is changed Looks what the new position is Sends position to the database where it is run SQL query Emulator Get reponse from database ConnDB: Connects server to database
  • 7. Code Set request and response Dynamic Web. Servlet ... protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String point = request.getParameter("point"); if("location".equalsIgnoreCase(point)) { Location location = new Location(); Location.getLocation(request, response); } } ... Connects server and database Dynamic Web. Conection to database ... private Connection connection = null; public Connection getConn() { Class.forName("org.postgresql.Driver").newInstance(); String url = "jdbc:postgresql://localhost:5432/postgres" ; connection = DriverManager.getConnection(url, "postgres" , "postgres" ); } ...
  • 8. Code Telling the database how to store the records Dynamic Web. Location ... ConnDB conndb = new ConnDB(); String updateSQL = "insert into allPositions(reportlat, reportlon) select " + lat + ", " + lon; connect = conndb.getConn(); Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); stmt.executeUpdate(updateSQL); Statement stmt2 = connect.createStatement(); stmt2.executeQuery("select avg(reportlat) avgreportlat,avg(reportlon) avgreportlon from allPositions"); ResultSet rs = stmt2.getResultSet(); rs.next(); double avglon = rs.getDouble(1); double avglat = rs.getDouble(2); DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.writeUTF("Succeed:" + avglon + ":" + avglat); ... Sending a SQL query to get back the average of all latitude and longitude values that are already store in the database
  • 9. Code Displaying map Main_Activity. OnCreate public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); mapView = (MapView) this.findViewById(R.id.mapview); mapView.setTileSource(TileSourceFactory.MAPNIK); mapView.setBuiltInZoomControls(true); mapView.setMultiTouchControls(true); mapController = mapView.getController(); GPS mapController.setZoom(11); point = new GeoPoint(59351756, 18057822); mapController.setCenter(point); mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*1000, 10,locListener); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Setting zoom Label = (TextView)findViewById(R.id.Label); } Label to show average point coordinates
  • 10. Code Main_Activity. OnLocationChanged ... Connect to the server url = new URL(strUrl); HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setRequestMethod("POST"); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); urlConn.setRequestProperty("Charest", "utf-8"); urlConn.connect(); Sending latitude and DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream()); longitude from current dop.writeBytes("point=" + URLEncoder.encode("location","utf-8")); dop.writeBytes("&lon=" + URLEncoder.encode(Double.toString(Lon),"utf-8")); positionto the server dop.writeBytes("&lat=" + URLEncoder.encode(Double.toString(Lat),"utf-8")); dop.flush(); dop.close(); DataInputStream dis = new DataInputStream(urlConn.getInputStream()); String locPassage = dis.readUTF(); String[] mystrings = locPassage.split(":"); AVGLat = Double.parseDouble(mystrings[1]); Reading latitude and longitude AVGLon = Double.parseDouble(mystrings[2]); noavgyet = false; of the average point of all recorded points and display displayLabel(locPassage); ... it in the label
  • 11. Code Setting the OSM display Main_Activity. Activiy_main.xml ... <org.osmdroid.views.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" /> Setting the label <TextView android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_margin="5dip" android:text="Welcome!" /> ... Drawing the average point Main_Activity .OnDraw ... if (!noavgyet) { GeoPoint pointavg = new GeoPoint((int)(AVGLat*1e6), (int)(AVGLon*1e6)); Paint paint2 = new Paint(); paint2.setColor(Color.GREEN); Point screenPoint2 = new Point(); mapView.getProjection().toPixels(pointavg, screenPoint2); Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.dot2); canvas.drawBitmap(bmp2, screenPoint2.x, screenPoint2.y, paint2); ...
  • 12. Running the aplication Simulate GPS with Dalvik Debug Monitor Server KML file with 5 points in Vaxholm -- Table: allpositions Database -- DROP TABLE allpositions; CREATE TABLE allpositions Allpositions table ( With 2 columns: reportlat double precision, reportlon double precision reportlat ) reportlon WITH ( OIDS=FALSE ); ALTER TABLE allpositions OWNER TO postgres;
  • 13. Running the aplication Current point Average point
  • 14. Use of the app Imagine you want to build a factory in a city with a certain number of houses Assume that we know where future workers live Collect the coordinates from their houses positions Get average position coordinates This minimizes the total travelling distance from workers houses to the factory
  • 15. What’s next • Add a reset button to clear records from the database • Add a button for getting GPS coordinates when pushed • Sharing location between users • Drawing all recorded points in the display
  • 16. Thank you! Video demostration

Editor's Notes

  • #9: createStatement()           Creates a Statement object for sending SQL statements to the database