11. Geolocation public static Location getLastKnownLocation() { LocationManageraLocationManager = (LocationManager) MyApplication.getInstance().getSystemService(Context.LOCATION_SERVICE); if (aLocationManager != null) { // Should get the last in time location, comparing location.getTime() ? Location gpsLocation = aLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location networkLocation = aLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location location = getLastLocation(gpsLocation, networkLocation); if (location != null) return location; else { Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); String provider = aLocationManager.getBestProvider(crit, true); location = aLocationManager.getLastKnownLocation(provider); if (location != null) return location; } }
12. return null; } private static Location getLastLocation(Location gpsLocation, Location networkLocation) { if (gpsLocation!=null) return gpsLocation; return networkLocation; } public static JSONObjectgetLastKnownLocationJsonGeoLocationInfo() { Location location = getLastKnownLocation(); JSONObject result = new JSONObject(); if (location!=null) result = locationToJson(location); return result; } public static void requestLocationUpdates(Integer minAccuracy, Integer timeout, booleanincludeHeadingAndSpeed) {
13. LocationManagerlocationManager = (LocationManager) MyApplication.getInstance().getSystemService(Context.LOCATION_SERVICE); String provider = getBestProviderFromCriteria(includeHeadingAndSpeed, locationManager); locationManager.requestLocationUpdates(provider, 0, 0, locationListener); } public static Location getLocationGeoLocationInfo(Integer minAccuracy, Integer timeout, booleanincludeHeadingAndSpeed) { // Date startTime = new Date(); //default to return Location location = null; LocationManagerlocationManager = (LocationManager) MyApplication.getInstance().getSystemService(Context.LOCATION_SERVICE); String provider = getBestProviderFromCriteria(includeHeadingAndSpeed, locationManager); location = locationManager.getLastKnownLocation(provider); long difLocInSeconds = 0; if (location!=null) {
14. difLocInSeconds = getDifInSeconds(location.getTime(), startTime.getTime()); } while(location==null //has no location || (minAccuracy!=0 && (!location.hasAccuracy() || location.getAccuracy()> minAccuracy)) //has not accuracy || difLocInSeconds>tenMinutes ) //is old location { //wait one sec to new location to arrive try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (newCurrentLocation!=null) { location = newCurrentLocation; difLocInSeconds = 0; } Date endTime = new Date(); long difInSeconds = getDifInSeconds(startTime.getTime(), endTime.getTime());
15. if (difInSeconds>timeout) { break; } } //default to return if(location==null) location = getLastKnownLocation(); return location; } public static JSONObjectgetLocationJsonGeoLocationInfo(Integer minAccuracy, Integer timeout, booleanincludeHeadingAndSpeed) { Location location = getLocationGeoLocationInfo(minAccuracy, timeout, includeHeadingAndSpeed); //return result JSONObject result = new JSONObject(); if (location!=null) { result = locationToJson(location);
16. Services.Log.info("getLocationInfo", "Location: " + location.toString()); } return result; } private static long getDifInSeconds(long startTime, long endTime) { long dif = endTime - startTime; long difInSeconds = dif / 1000; return difInSeconds; } public static void removeLocationUpdates(Integer minAccuracy, Integer timeout, booleanincludeHeadingAndSpeed) { LocationManagerlocationManager = (LocationManager) MyApplication.getInstance().getSystemService(Context.LOCATION_SERVICE); locationManager.removeUpdates( locationListener); } private static String getBestProviderFromCriteria( booleanincludeHeadingAndSpeed, LocationManagerlocationManager) { //Calculate new location with the criteria.
17. Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); crit.setAltitudeRequired(false); crit.setBearingRequired(includeHeadingAndSpeed); crit.setCostAllowed(true); String provider = locationManager.getBestProvider(crit, true); return provider; } private static JSONObjectlocationToJson(Location location) { JSONObjectjsonProperty = new JSONObject(); try { jsonProperty.put("Location", String.valueOf(location.getLatitude()) + "," + String.valueOf(location.getLongitude()) ); jsonProperty.put("Description", "LocationInfo (" + location.getProvider() + ")"); Date date = new Date(); date.setTime(location.getTime()); jsonProperty.put("Time", Services.Strings.getDateTimeStringForServer(date) ); jsonProperty.put("Precision", String.valueOf(location.getAccuracy()) ); if (location.hasBearing()) jsonProperty.put("Heading", String.valueOf(location.getBearing()));
18. else jsonProperty.put("Heading", String.valueOf(-1)); if (location.hasSpeed()) jsonProperty.put("Speed", String.valueOf(location.getSpeed())); else jsonProperty.put("Speed", String.valueOf(-1)); } catch (JSONException e) { e.printStackTrace(); Services.Log.Error("locationToJson", "Exception in JSONObject.put()", e); } return jsonProperty; } public static String getLocationString(Location myLocation) { if (myLocation!=null) return String.valueOf(myLocation.getLatitude()) + "," + String.valueOf(myLocation.getLongitude() ); return ""; } private static final LocationListenerlocationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) {
19. } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(Location location) { //update my location Services.Log.info("onLocationChanged", "Location: " + location.toString()); newCurrentLocation = location; } };
20. Beneficios Integración con aplicaciones desarrolladas con Genexus. Integración con sistemas no Genexus. Reutilización de los objetos Genexus. No requiere inversión en capacitación. Fácil mantenimiento para los clientes. Deploy en varios OS. Seguridad Integrada.
22. La evolución continua Line of businessapplications Displayapplications Transactionapplications
23. Resumen 1 SmartDevices en la actualidad 2 LBA vs CA 3 Necesidades del mercado corporativo 4 Beneficios GxEv2
24. Asesor del pentágono Coronel JhonBoyd “Aquel que gana la batalla no es el más fuerte , ni siquiera el más valiente, es aquel que tiene la mayor capacidad de adaptarse a los cambios”