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
Nova Api de Localização Android
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
José Caique Oliveira
November 10, 2017
Programming
0
95
Nova Api de Localização Android
Slides usados no TDC Porto Alegre
José Caique Oliveira
November 10, 2017
Tweet
Share
More Decks by José Caique Oliveira
See All by José Caique Oliveira
Kotlin Flow
jcaiqueoliveira
0
120
Coroutines And Flow
jcaiqueoliveira
2
120
Testing your app
jcaiqueoliveira
0
310
Modularizando seu app
jcaiqueoliveira
0
73
Arquitetura para android
jcaiqueoliveira
6
320
Kotlin por onde começar?
jcaiqueoliveira
1
98
Introdução ao Android
jcaiqueoliveira
1
89
Arquitetura para projetos Android
jcaiqueoliveira
1
240
Kotlin 1.1
jcaiqueoliveira
0
140
Other Decks in Programming
See All in Programming
MUSUBIXとは
nahisaho
0
130
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
Fragmented Architectures
denyspoltorak
0
150
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
110
CSC307 Lecture 04
javiergs
PRO
0
660
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
270
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.1k
AtCoder Conference 2025
shindannin
0
1.1k
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
720
CSC307 Lecture 03
javiergs
PRO
1
490
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
How GitHub (no longer) Works
holman
316
140k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
84
Evolving SEO for Evolving Search Engines
ryanjones
0
120
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
A designer walks into a library…
pauljervisheath
210
24k
Transcript
Nova API de localização para Android Diminuindo fricção
Caique Oliveira Graduado em Ciência da computação - UFS Android
developer - Stone Apresentação
Trabalhando com localização no Android
Implementar GooglePlayServicesClient - ConnectionCallbacks - OnConnectionFailedListener
ConnectionCallbacks override fun onConnected(p0: Bundle?){ } override fun onConnectionSuspended(p0: Int){
}
OnConnectionFailedListener override fun onConnectionFailed(p0: ConnectionResult) { }
Configurar GoogleApiClient fun initGoogleApiClient() { if (mGoogleApiClient != null) {
mGoogleApiClient = GoogleApiClient.Builder( this) .addConnectionCallbacks( this) .addOnConnectionFailedListener( this) .addApi(LocationServices. API) .build() } mGoogleApiClient?.connect() }
Conectar ao Play Services override fun onStart() { mGoogleApiClient?.connect() super.onStart()
}
Desconectar de acordo com o ciclo de vida override fun
onStop() { mGoogleApiClient?.disconnect() super.onStop() }
fun getLocation(): Location { return LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient) }
Meu Deus do Céu
Todo app é a mesma coisa
“É realmente necessário que eu mesmo controle o GoogleApiClient?”
“Eu realmente preciso controlar o ciclo de vida dele?”
Android Architecture Components
Android Architecture Components - Menor escrita de código - Framework
gerencia o ciclo de vida - Traz uma melhor experiência para o desenvolvedor
Reduzindo o atrito ao trabalhar com Location
implementation ‘com.google.android.gms:play-services-location:11.6.0’
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.e("location", location.toString()) })
implementa OnFailureListener override fun onFailure(p0: Exception) { val statusCode =
(p0 as ApiException).statusCode when (statusCode) { RESOLUTION_REQUIRED -> { //Fix in Settings." } SETTINGS_CHANGE_UNAVAILABLE -> { //Fix in Settings." } } }
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.v("location", location.toString()) }).addOnFailureListener(this)
Location Updates LocationServices.getFusedLocationProviderClient(this) .requestLocationUpdates( locationRequest = mLocationRequest, locationCallback = mLocationCallback,
looper = Looper.myLooper())
Location Updates - Callback val mLocationCallback = object : LocationCallback()
{ override fun onLocationResult(result: LocationResult?) { super.onLocationResult(result) Log.v("location",locationResult?.lastLocation?.toString()) } }
Location Updates - Request val mLocationRequest = LocationRequest() .setInterval(UPDATE_INTERVAL_IN_MILLISECONDS) .setFastestInterval(UPDATE_INTERVAL_IN_MILLISECONDS)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
Temos agora o foco para obter de forma simples uma
localização ou resolver um problema
Obrigado! twitter: @_josecaique email:
[email protected]
slack android dev br: caique
github: jcaiqueoliveira https://goo.gl/E1QsJg
Referências https://goo.gl/dLZ8X2 https://goo.gl/itG6pa
enter.stone.com.br