Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Geofencing avec Google Places
Search
Robin Caroff
January 24, 2017
Programming
0
39
Geofencing avec Google Places
Présentation du Geofencing sur Android avec Google Places.
Robin Caroff
January 24, 2017
Tweet
Share
More Decks by Robin Caroff
See All by Robin Caroff
Screenshot Testing pour Compose Preview
robincaroff
0
65
Migration Android 15
robincaroff
0
8
Migration Android 14
robincaroff
1
120
À la découverte du développement mobile (sans les maux de tête)
robincaroff
0
61
À la découverte du développement mobile (sans les maux de tête) - SHORT
robincaroff
0
110
Rex - Migration Android 13
robincaroff
0
59
App-Elles - Exemple de tech for good mobile à l'heure du confinement
robincaroff
0
110
From Dagger to Dagger Hilt
robincaroff
0
270
Android Async Talk
robincaroff
1
120
Other Decks in Programming
See All in Programming
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
590
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
710
Amazon S3 TablesとAmazon S3 Metadataを触ってみた / 20250201-jawsug-tochigi-s3tables-s3metadata
kasacchiful
0
160
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
250
Immutable ActiveRecord
megane42
0
140
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
480
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
バックエンドのためのアプリ内課金入門 (サブスク編)
qnighy
8
1.8k
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
560
技術を根付かせる / How to make technology take root
kubode
1
250
Writing documentation can be fun with plugin system
okuramasafumi
0
120
ソフトウェアエンジニアの成長
masuda220
PRO
10
1.1k
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Bootstrapping a Software Product
garrettdimon
PRO
306
110k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
550
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
It's Worth the Effort
3n
184
28k
Docker and Python
trallard
44
3.3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Transcript
GEOFENCING AVEC GOOGLE PLACES ANDROID NANTES - JANVIER 2017 Par
@RobinCaroff
LE PROBLÈME
GEOFENCING https://developer.android.com
GEOFENCING https://developers.google.com
GEOFENCING Dépendances Gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.google.android.gms:play-services:9.4.0' }a
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' a
compile 'com.google.android.gms:play-services-location:9.4.0' }a GEOFENCING Dépendances Gradle
GEOFENCING dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1'
a compile 'com.google.android.gms:play-services-location:9.4.0' compile 'com.google.android.gms:play-services-maps:9.4.0' compile 'com.google.android.gms:play-services-places:9.4.0' }a Dépendances Gradle
PERMISSIONS <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.robincaroff.mygeofencer" > <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application> ... </application> </manifest> Manifest
PERMISSIONS <application android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/maps_apikey"/> ... <service
android:name=".services.GeofenceTransitionsIntentService"/> </application> Manifest
PERMISSIONS <application android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/maps_apikey"/> ... <service
android:name=".services.GeofenceTransitionsIntentService"/> </application> Manifest pour Place Picker
PERMISSIONS La technique
PERMISSIONS La technique du
PERMISSIONS La technique du SPLASH SCREEN
PERMISSIONS @Override protected void onCreate(Bundle savedInstanceState) { ... checkPermissions(); }a
private void checkPermissions() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } else { goToMainActivity(); }b }c
PERMISSIONS @Override protected void onCreate(Bundle savedInstanceState) { ... checkPermissions(); }a
private void checkPermissions() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } else { goToMainActivity(); }b }c
GOOGLE API CLIENT protected synchronized void buildGoogleApiClient() { mGoogleApiClient =
new GoogleApiClient .Builder(context) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .addApi(Places.GEO_DATA_API) .addApi(Places.PLACE_DETECTION_API) .build(); }
GOOGLE API CLIENT @Override protected void onStart() { super.onStart(); mGoogleApiClient.connect();
} @Override protected void onStop() { super.onStop(); mGoogleApiClient.disconnect(); }
GEOFENCES https://developer.android.com
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
CREATE A GEOFENCE Geofence geofence = new Geofence.Builder() .setRequestId(STRING_ID) .setCircularRegion(
LATITUDE, LONGITUDE, RADIUS_IN_METERS ) .setExpirationDuration(EXPIRATION_IN_MILLISECONDS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build());
GEOFENCING REQUEST private GeofencingRequest getGeofencingRequest() { GeofencingRequest.Builder builder = new
GeofencingRequest.Builder(); builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER); builder.addGeofences(mGeofenceList); return builder.build(); }
GEOFENCE INTENT private PendingIntent getGeofencePendingIntent() { if (mGeofencePendingIntent != null)
{ return mGeofencePendingIntent; } Intent intent = new Intent(this, GeofenceTransitionsIntentService.class); return PendingIntent.getService(this, 0, intent, PendingIntent. FLAG_UPDATE_CURRENT); }
START / STOP GEOFENCING LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent() ).setResultCallback(this); LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient, getGeofencePendingIntent() ).setResultCallback(this);
START / STOP GEOFENCING LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent() ).setResultCallback(this); LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient, getGeofencePendingIntent() ).setResultCallback(this);
None
NOT BORING AT ALL…
SHOW ME HOW IT WORKS !
TESTS ▸ Real testing ▸ Mock location apps ▸ Emulator
▸ Mock location provider
LIMITATIONS
LIMITATIONS 100 geofences par application et par utilisateur (pour un
device)
BEST PRACTICES ▸ Réduire l’utilisation de la batterie en changeant
la ‘réactivité’ des notifications ▸ Optimiser les rayons de geofences ▸ Surveiller seulement quand c’est nécessaire ▸ Utiliser les transitions DWELL plutôt que ENTER