• Nie Znaleziono Wyników

Introducing to Location in Android

N/A
N/A
Protected

Academic year: 2021

Share "Introducing to Location in Android"

Copied!
18
0
0

Pełen tekst

(1)

Introducing to Location in Android

LOCATION

IS EVERYTHING

Kamil Lelonek

Kamil.Lelonek@student.pwr.wroc.pl

Kamil Lelonek

Kamil.Lelonek@student.pwr.wroc.pl

(2)

What we gonna talk about?

Introduction to GEOgraphy

• How we „describe” the Earth?

• How we calculate coordinates?

• Important issues to avoid problems

Finding user location

• Prepare to coding

• Ways to obtain current position

• This time emulator is helpful

Developing Maps application

• GeoCoding

• Good old Google Maps API v1

New look and feel Google Maps API v2

Summary

• Navigation

• PRO tips for advanced users

• Q&A

(3)

Let’s go back to school

º - degrees

’ - minutes

’’ - seconds

East (E) West (W)

(N)

(S)

(4)

How to calculate it?

23º25’24’’ S

23º25’24’’ S → – 23,439167 (double)

(int) = 1E6 * (double) → – 23439167 (int)

(5)

Attention

Attention Problems Problems Extras Extras

- Positive and Negative values

- Latutude goes first

Calcuation problems

- Altitude

- Azimuth

- Speed

(6)

Get prepared

Permissions

o ACCESS_MOCK_LOCATION - emulator o ACCESS_COARSE_LOCATION - approximate o ACCESS_FINE_LOCATION - precise

o ACCESS_LOCATION_EXTRA_COMMANDS o INSTALL_LOCATION_PROVIDER

LocationManager

LocationProvider

LocationListener

(7)

LocationManager

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

List<String> providersAll = locationManager.getAllProviders();

List<String> providersEnabled = locationManager.getProviders(true);

Location lastKnownLocation = locationManager.getLastKnownLocation(String provider);

Location Location

double getLatitude() double getLongitude()

if(hasAltitude()) getAltitude()

float distanceTo(Location dest)

String getProvider()

(8)

Criterias

String getBestProvider(Criteria criteria, boolean enabledOnly)

Criteria criteria = new Criteria();

int ACCURACY_COARS int ACCURACY_FINE int ACCURACY_HIGH int ACCURACY_LOW int ACCURACY_MEDIUM int NO_REQUIREMENT int POWER_HIGH

int POWER_LOW int POWER_MEDIUM

void setAccuracy(int accuracy)

void setAltitudeRequired(boolean altitudeRequired) void setBearingAccuracy(int accuracy)

void setBearingRequired(boolean bearingRequired) void setCostAllowed(boolean costAllowed)

void setHorizontalAccuracy(int accuracy) void setPowerRequirement(int level)

void setSpeedAccuracy(int accuracy)

void setSpeedRequired(boolean speedRequired)

void setVerticalAccuracy(int accuracy)

(9)

LocationProviders

LocationProvider getProvider(String name)

boolean hasMonetaryCost() boolean requiresCell() boolean requiresNetwork() boolean requiresSatellite() boolean supportsAltitude() boolean supportsBearing() boolean supportsSpeed()

of 24

(10)

LocationListene r

new LocationListener() {

@Override

public void onStatusChanged(String provider, int status, Bundle extras) {}

@Override

public void onProviderEnabled(String provider) {}

@Override

public void onProviderDisabled(String provider) {}

@Override

public void onLocationChanged(Location location) {}

}

new LocationListener() {

@Override

public void onStatusChanged(String provider, int status, Bundle extras) {}

@Override

public void onProviderEnabled(String provider) {}

@Override

public void onProviderDisabled(String provider) {}

@Override

public void onLocationChanged(Location location) {}

}

void requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)

(11)

Using Emulator and DDMS

> telnet localhost 5554

> geo fix -122.084096 37.422005

(12)

GeoCoding

private void doInBackground() { List<Address> foundGeocode;

double latitude;

double longitude;

try {

foundGeocode = new Geocoder(this).getFromLocationName("ADDRESS", N);

for(int n = 0; n < N; n++) {

latitude = foundGeocode.get(n).getLatitude();

longitude = foundGeocode.get(n).getLongitude();

} }

catch(IOException) { // Log.e(...);

}

}

(13)

Google Maps Android v1 API (Deprecated?)

Note:

Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012.

This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1.

However, apps using v1 will continue to work on devices. Existing and new developers

are encouraged to use Google Maps Android API v2.

(14)

Google Maps Android v1 API

private void setUpMap() {

mapView = (MapView) findViewById(R.id.mapView);

mapView.setBuiltInZoomControls(true);

mapView.setOnSingleTapListener(new OnSingleTapListener() {

@Override public boolean onSingleTap(MotionEvent e) {}

});

mapOverlays = mapView.getOverlays();

myLocationOverlay = new MyLocationOverlay(this, mapView);

myLocationOverlay.enableMyLocation();

myLocationOverlay.enableCompass();

myLocationOverlay.runOnFirstFix(new Runnable() {

@Override public void run() {

MapController mapController = mapView.getController();

mapController.animateTo(currentLocation);

mapController.setZoom(17);

mapView.getOverlays().add(myLocationOverlay);

} });

mapOverlays.add(myLocationOverlay);

(15)

Google Maps Android API v2

(16)

Google Maps Android API v2

Google Maps Android API v2

(17)

Weaknesses:

• No Android Emulator suport!

• Poor documented…

• Requires powerfull device to display 3D view

// Construct a CameraPosition focusing on PWr // and animate the camera to that position.

CameraPosition cameraPosition = new CameraPosition.Builder()

.target(new LatLng(51.107359,17.059974)) // Sets the center of the map to C-13 .zoom(17) // Sets the zoom

.bearing(90) // Sets the orientation of the camera to east .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

Google Maps Android API v2

Google Maps Android

API v2

(18)

Summary

It would be quite nice to remember and take care about:

Efficency

Battery saving Networking

data

Cytaty

Powiązane dokumenty

In constructing embeddings of Boolean algebras and extensions of their automorphisms, we have to avoid the following problem: It is well known that there are gaps in P (ω)/fin which

However, a drawback of this spectral characteriza- tion of the decomposability is that if the decomposition of a given Boolean function f is possible, it may not be immediately

The basic idea is to consider sequentially continuous and strictly posi- tive functionals defined on σ-complete Boolean algebras, in the sequel called Mazur functionals..

Four-part semigroups form a new class of semigroups which became im- portant when sets of Boolean operations which are closed under the binary superposition operation f + g := f

In this paper an Internet based implementation is proposed for simplifying two to four-variable Boolean functions, using a Modified Quine-McCluskey (M Q-M) method.. The M Q-M

In our approach to Boolean systems based on the partial order structure a special role is played by various types of binary operations (partial and full) of difference.. In this

It seems quite likely that for n-bit Boolean functions each projection direction will separate the maximum number of functions for k ≈ 2 n /2, and that learning the best projection

boolean hasMonetaryCost() boolean requiresCell() boolean requiresNetwork() boolean requiresSatellite() boolean supportsAltitude() boolean supportsBearing() boolean supportsSpeed().