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
44
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
77
Migration Android 15
robincaroff
0
12
Migration Android 14
robincaroff
1
140
À la découverte du développement mobile (sans les maux de tête)
robincaroff
0
72
À la découverte du développement mobile (sans les maux de tête) - SHORT
robincaroff
0
130
Rex - Migration Android 13
robincaroff
0
63
App-Elles - Exemple de tech for good mobile à l'heure du confinement
robincaroff
0
110
From Dagger to Dagger Hilt
robincaroff
0
290
Android Async Talk
robincaroff
1
130
Other Decks in Programming
See All in Programming
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
3
470
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
170
Goで作る、開発・CI環境
sin392
0
230
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
530
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
100
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
9
5.1k
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
820
Discover Metal 4
rei315
2
130
VS Code Update for GitHub Copilot
74th
2
640
XP, Testing and ninja testing
m_seki
3
240
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Site-Speed That Sticks
csswizardry
10
690
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Automating Front-end Workflow
addyosmani
1370
200k
Testing 201, or: Great Expectations
jmmastey
43
7.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Statistics for Hackers
jakevdp
799
220k
We Have a Design System, Now What?
morganepeng
53
7.7k
Adopting Sorbet at Scale
ufuk
77
9.5k
Rails Girls Zürich Keynote
gr2m
95
14k
Typedesign – Prime Four
hannesfritz
42
2.7k
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