SlideShare a Scribd company logo
1 of 16
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

G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門Tsuyoshi Yamamoto
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackNelson Glauber Leal
 
State managment in a world of hooks
State managment in a world of hooksState managment in a world of hooks
State managment in a world of hooks500Tech
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Rafael Soto
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017Shem Magnezi
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210Mahmoud Samir Fayed
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Luca Lusso
 
Building android apps with kotlin
Building android apps with kotlinBuilding android apps with kotlin
Building android apps with kotlinShem Magnezi
 
097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestiónGeneXus
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile servicesAymeric Weinbach
 
Arquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackArquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackNelson Glauber Leal
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreStephane Belkheraz
 
Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruangSanSan Yagyoo
 
The Ring programming language version 1.10 book - Part 79 of 212
The Ring programming language version 1.10 book - Part 79 of 212The Ring programming language version 1.10 book - Part 79 of 212
The Ring programming language version 1.10 book - Part 79 of 212Mahmoud Samir Fayed
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
Introdução ao Desenvolvimento Android com Kotlin
Introdução ao Desenvolvimento Android com KotlinIntrodução ao Desenvolvimento Android com Kotlin
Introdução ao Desenvolvimento Android com KotlinNelson Glauber Leal
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Yonatan Levin
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerDarwin Durand
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard LibraryNelson Glauber Leal
 

What's hot (20)

G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
State managment in a world of hooks
State managment in a world of hooksState managment in a world of hooks
State managment in a world of hooks
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Building android apps with kotlin
Building android apps with kotlinBuilding android apps with kotlin
Building android apps with kotlin
 
097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
Arquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackArquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com Jetpack
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruang
 
Hadoop gets Groovy
Hadoop gets GroovyHadoop gets Groovy
Hadoop gets Groovy
 
The Ring programming language version 1.10 book - Part 79 of 212
The Ring programming language version 1.10 book - Part 79 of 212The Ring programming language version 1.10 book - Part 79 of 212
The Ring programming language version 1.10 book - Part 79 of 212
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
Introdução ao Desenvolvimento Android com Kotlin
Introdução ao Desenvolvimento Android com KotlinIntrodução ao Desenvolvimento Android com Kotlin
Introdução ao Desenvolvimento Android com Kotlin
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 

Viewers also liked

Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Galileo 6 satellieten gelanceerd. Een statusoverzicht.Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Galileo 6 satellieten gelanceerd. Een statusoverzicht.Hydrographic Society Benelux
 
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူWhy has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူZaw Aung
 
Advance presentation patras
Advance presentation patrasAdvance presentation patras
Advance presentation patrasYannis Koliousis
 
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...Andrew Neville
 
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...
2014.04   dubai - metrology and ramses synthetic baseline positioning - final...2014.04   dubai - metrology and ramses synthetic baseline positioning - final...
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...James Titcomb
 
Opportunities for the Hydrographic Sector Using Satellite Observation Services
Opportunities for the Hydrographic Sector Using Satellite Observation ServicesOpportunities for the Hydrographic Sector Using Satellite Observation Services
Opportunities for the Hydrographic Sector Using Satellite Observation ServicesHydrographic Society Benelux
 
E Mar Piraeus Presentation Welcome Address by Jenny Rainbird
E Mar Piraeus Presentation Welcome Address by Jenny RainbirdE Mar Piraeus Presentation Welcome Address by Jenny Rainbird
E Mar Piraeus Presentation Welcome Address by Jenny RainbirdYannis Koliousis
 
De eerste GLONASS-K Satellieten en de CDMA formaten
De eerste GLONASS-K Satellieten en de CDMA formatenDe eerste GLONASS-K Satellieten en de CDMA formaten
De eerste GLONASS-K Satellieten en de CDMA formatenHydrographic Society Benelux
 
Enabling RTK-like positioning offshore using the global VERIPOS GNSS network
Enabling RTK-like positioning offshore using the global VERIPOS GNSS networkEnabling RTK-like positioning offshore using the global VERIPOS GNSS network
Enabling RTK-like positioning offshore using the global VERIPOS GNSS networkHydrographic Society Benelux
 

Viewers also liked (20)

Positioning the Solitaire
Positioning the SolitairePositioning the Solitaire
Positioning the Solitaire
 
Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Galileo 6 satellieten gelanceerd. Een statusoverzicht.Galileo 6 satellieten gelanceerd. Een statusoverzicht.
Galileo 6 satellieten gelanceerd. Een statusoverzicht.
 
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူWhy has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
Why has the japan succeeded ဘာသာျပန္ - ေမာင္ထြန္းသူ
 
Advance presentation patras
Advance presentation patrasAdvance presentation patras
Advance presentation patras
 
Whalsay Slides
Whalsay SlidesWhalsay Slides
Whalsay Slides
 
CV.June 2015
CV.June 2015CV.June 2015
CV.June 2015
 
Positioning challenges on fallpipe vessels
Positioning challenges on fallpipe vesselsPositioning challenges on fallpipe vessels
Positioning challenges on fallpipe vessels
 
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
 
GPS Status en Evolutie
GPS Status en EvolutieGPS Status en Evolutie
GPS Status en Evolutie
 
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...
2014.04   dubai - metrology and ramses synthetic baseline positioning - final...2014.04   dubai - metrology and ramses synthetic baseline positioning - final...
2014.04 dubai - metrology and ramses synthetic baseline positioning - final...
 
Dark diamond
Dark diamondDark diamond
Dark diamond
 
Opportunities for the Hydrographic Sector Using Satellite Observation Services
Opportunities for the Hydrographic Sector Using Satellite Observation ServicesOpportunities for the Hydrographic Sector Using Satellite Observation Services
Opportunities for the Hydrographic Sector Using Satellite Observation Services
 
E Mar Piraeus Presentation Welcome Address by Jenny Rainbird
E Mar Piraeus Presentation Welcome Address by Jenny RainbirdE Mar Piraeus Presentation Welcome Address by Jenny Rainbird
E Mar Piraeus Presentation Welcome Address by Jenny Rainbird
 
De eerste GLONASS-K Satellieten en de CDMA formaten
De eerste GLONASS-K Satellieten en de CDMA formatenDe eerste GLONASS-K Satellieten en de CDMA formaten
De eerste GLONASS-K Satellieten en de CDMA formaten
 
Drones, een overzicht
Drones, een overzichtDrones, een overzicht
Drones, een overzicht
 
Konsberg K-DP Guide
Konsberg K-DP GuideKonsberg K-DP Guide
Konsberg K-DP Guide
 
Work Ethics
Work EthicsWork Ethics
Work Ethics
 
Enabling RTK-like positioning offshore using the global VERIPOS GNSS network
Enabling RTK-like positioning offshore using the global VERIPOS GNSS networkEnabling RTK-like positioning offshore using the global VERIPOS GNSS network
Enabling RTK-like positioning offshore using the global VERIPOS GNSS network
 
20161102 agmjht
20161102 agmjht20161102 agmjht
20161102 agmjht
 
Gravity Expeditions at Sea
Gravity Expeditions at SeaGravity Expeditions at Sea
Gravity Expeditions at Sea
 

Similar to Average- An android project

What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - ComponentsVisual Engineering
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication developmentGanesh Gembali
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSuzquiano
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Codemotion
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native appsInnovationM
 
What's the deal with Android maps?
What's the deal with Android maps?What's the deal with Android maps?
What's the deal with Android maps?Chuck Greb
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!Sébastien Levert
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Building cross-platform mobile apps with React Native (Jfokus 2017)
Building cross-platform mobile apps with React Native (Jfokus 2017)Building cross-platform mobile apps with React Native (Jfokus 2017)
Building cross-platform mobile apps with React Native (Jfokus 2017)Maarten Mulders
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
 
Android Support Library
Android Support LibraryAndroid Support Library
Android Support LibraryAlexey Ustenko
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialMax Kleiner
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
 

Similar to Average- An android project (20)

Mobile Web 5.0
Mobile Web 5.0Mobile Web 5.0
Mobile Web 5.0
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - Components
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
mobl
moblmobl
mobl
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
What's the deal with Android maps?
What's the deal with Android maps?What's the deal with Android maps?
What's the deal with Android maps?
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Building cross-platform mobile apps with React Native (Jfokus 2017)
Building cross-platform mobile apps with React Native (Jfokus 2017)Building cross-platform mobile apps with React Native (Jfokus 2017)
Building cross-platform mobile apps with React Native (Jfokus 2017)
 
Android 3
Android 3Android 3
Android 3
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
Android Support Library
Android Support LibraryAndroid Support Library
Android Support Library
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps Tutorial
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 

More from Ipsit Dash

Land Reforms : An overview
Land Reforms : An overviewLand Reforms : An overview
Land Reforms : An overviewIpsit Dash
 
Water Sector Debate
Water Sector DebateWater Sector Debate
Water Sector DebateIpsit Dash
 
Tirupur Water Supply and Sanitation
Tirupur Water Supply and SanitationTirupur Water Supply and Sanitation
Tirupur Water Supply and SanitationIpsit Dash
 
Spatial Data Mining : Seminar
Spatial Data Mining : SeminarSpatial Data Mining : Seminar
Spatial Data Mining : SeminarIpsit Dash
 
Change Detection Dubai
Change Detection DubaiChange Detection Dubai
Change Detection DubaiIpsit Dash
 
Implementation of INS-GPS
Implementation of INS-GPSImplementation of INS-GPS
Implementation of INS-GPSIpsit Dash
 

More from Ipsit Dash (6)

Land Reforms : An overview
Land Reforms : An overviewLand Reforms : An overview
Land Reforms : An overview
 
Water Sector Debate
Water Sector DebateWater Sector Debate
Water Sector Debate
 
Tirupur Water Supply and Sanitation
Tirupur Water Supply and SanitationTirupur Water Supply and Sanitation
Tirupur Water Supply and Sanitation
 
Spatial Data Mining : Seminar
Spatial Data Mining : SeminarSpatial Data Mining : Seminar
Spatial Data Mining : Seminar
 
Change Detection Dubai
Change Detection DubaiChange Detection Dubai
Change Detection Dubai
 
Implementation of INS-GPS
Implementation of INS-GPSImplementation of INS-GPS
Implementation of INS-GPS
 

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

  1. createStatement()           Creates a Statement object for sending SQL statements to the database