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
Migration Android 14
robincaroff
1
120
À la découverte du développement mobile (sans les maux de tête)
robincaroff
0
51
À la découverte du développement mobile (sans les maux de tête) - SHORT
robincaroff
0
100
Rex - Migration Android 13
robincaroff
0
58
App-Elles - Exemple de tech for good mobile à l'heure du confinement
robincaroff
0
110
From Dagger to Dagger Hilt
robincaroff
0
260
Android Async Talk
robincaroff
1
120
Feedback: How I brought Kotlin into my Room (short)
robincaroff
0
93
Other Decks in Programming
See All in Programming
良いユニットテストを書こう
mototakatsu
5
2k
useSyncExternalStoreを使いまくる
ssssota
6
1k
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
From Translations to Multi Dimension Entities
alexanderschranz
2
130
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Recoilを剥がしている話
kirik
5
6.6k
MCP with Cloudflare Workers
yusukebe
2
220
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
0
110
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
97
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
What's in a price? How to price your products and services
michaelherold
243
12k
Scaling GitHub
holman
458
140k
BBQ
matthewcrist
85
9.4k
Speed Design
sergeychernyshev
25
670
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Writing Fast Ruby
sferik
628
61k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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