Have a look at this code:
private void moveMapToMyLocation() { LocationManager locMan = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); Location loc = locMan.getLastKnownLocation(locMan.getBestProvider(crit, false)); CameraPosition camPos = new CameraPosition.Builder() .target(new LatLng(loc.getLatitude(), loc.getLongitude())) .zoom(12.8f) .build(); CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos); getMap().moveCamera(camUpdate); }
This is a method I made, you can place it somewhere in your custom MapFragment or in your Activity.
It's important to call this moment at the right time. We have to make sure that the map is loaded before we ask it to move to somewhere else:
- in custom MapFragment: call the method somewhere in onActivityCreated(Bundle)
- in Activity: call the method somewhere in onStart()
Moving the camera (your view of the map) around is possible by making a CameraPosition object, and using that to make the right CameraUpdate object.
Once we have our CameraUpdate object, we can choose to use moveCamera(CameraUpdate) or animateCamera(CameraUpdate). With moveCamera, the view will instantly change and with animateCamera you'll see the map moving on the screen towards the destination that we want. There are multiple arguments possible for these methods, please check the android API here for more information.
Good luck!
Hi, I thing you can do it shorter and readable :).
ReplyDeleteThis should have the same effect:
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.8f));
Indeed, I just showed it like this so people would get to know the CameraPosition class. There are more things you can add such as 'bearing' and 'tilt'. I didn't use this in this example.
DeleteThanks for sharing, Get more on Android Course
ReplyDeleteFind all latest mobile phone, smartphone, android phone,tab,all mobile phone review, latest technology, feature phone etc.
ReplyDeletehttps://mobilebaazar24.blogspot.com
https://mobilebaazar24.blogspot.com/2020/06/oppo-a9-mobile-price-in-bangladesh.html#more
https://mobilebaazar24.blogspot.com/2020/05/vivo-v19-pro-mobile-price-in-bangladesh.html
https://mobilebaazar24.blogspot.com/2020/06/oppo-f15-mobile-price-in-bangladesh.html#more
adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeleteno deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - tiktok takipçi satın al - instagram beğeni satın al - instagram beğeni satın al - google haritalara yer ekleme - btcturk güvenilir mi - izlenme-satin-al.com - numarasmsonay.com - borsagazete.com - takipcisatinals.com - izlenme-satin-al.com/youtube - google haritalara yer ekleme - altyapısız internet - mikrofiber havlu - forexbonus2020.com - tiktok jeton hilesi - tiktok beğeni satın al - microsoft word ücretsiz indir - misli apk indir - binance güvenilir mi - takipçi satın al - mikrofiber havlu - uc satın al - takipçi satın al - takipçi satın al - finanspedia.com
ReplyDeletetakipçi satın al
ReplyDeletetakipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
https://www.escortsmate.com - adana escort - adıyaman escort - afyon escort - ağrı escort - aksaray escort - amasya escort - ankara escort - antalya escort - ardahan escort - artvin escort - aydın escort - balıkesir escort - bartın escort - batman escort - bayburt escort - bilecik escort - bingöl escort - bitlis escort - bolu escort - burdur escort - bursa escort - çanakkale escort - çankırı escort - çorum escort - denizli escort - diyarbakır escort - düzce escort - edirne escort - elazığ escort - erzincan escort - erzurum escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - gümüşhane escort - hakkari escort - hatay escort - ığdır escort - ısparta escort - izmir escort - istanbul escort - karabük escort - karaman escort - kars escort
ReplyDeletetakipçi satın al
ReplyDeleteinstagram takipçi satın al
https://www.takipcikenti.com
marsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
bitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
perde modelleri
ReplyDeleteNumara Onay
mobil ödeme bozdurma
nft nasil alınır
ANKARA EVDEN EVE NAKLİYAT
Trafik sigortasi
DEDEKTÖR
Websitesi kurmak
ASK ROMANLARİ