android - setOnMyLocationChangeListener and setMyLocationEnabled arent work on map -
i doing written in link isn't working(image1)(line 46, 47 , 53) https://io2015codelabs.appspot.com/codelabs/fire-place#7
for image -> mapsactiviy.java
import android.location.location; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.support.v4.content.contextcompat; import android.view.viewtreeobserver; import android.widget.button; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.googlemap.onmylocationchangelistener; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.latlngbounds; public class mapsactivity extends fragmentactivity implements onmapreadycallback { private googlemap mmap; private latlngbounds.builder mbounds = new latlngbounds.builder(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); // set google maps supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } /** * map setup. called when googlemap available manipulate. */ @override public void onmapready(googlemap googlemap) { mmap = googlemap; // pad map controls make room button - note button may not have // been laid out yet. final button button = (button) findviewbyid(r.id.checkout_button); button.getviewtreeobserver().addongloballayoutlistener( new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { mmap.setpadding(0, button.getheight(), 0, 0); } } ); mmap.setmylocationenabled(true); mmap.setonmylocationchangelistener(new onmylocationchangelistener() { @override public void onmylocationchange(location location) { latlng ll = new latlng(location.getlatitude(), location.getlongitude()); addpointtoviewport(ll); // want grab location once, allow user pan , zoom freely. mmap.setonmylocationchangelistener(null); } }); } private void addpointtoviewport(latlng newpoint) { mbounds.include(newpoint); mmap.animatecamera(cameraupdatefactory.newlatlngbounds(mbounds.build(), findviewbyid(r.id.checkout_button).getheight())); } }
activity_maps.xml
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <button android:id="@+id/checkout_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/check_out" android:onclick="checkout"/> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context=".mapsactivity" android:name="com.google.android.gms.maps.supportmapfragment"/> </framelayout>
build.gradle(module: app)
apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion '23.0.3' defaultconfig { applicationid "com.sahikaaylin.checkout" minsdkversion 19 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } productflavors { } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.google.android.gms:play-services:9.0.1' compile 'com.firebase:firebase-client-android:2.3.1' compile 'com.android.support:appcompat-v7:23.4.0' }
for manifest.xml
<uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme" > <meta-data android:name="com.google.android.geo.api_key" android:value="@string/google_maps_key" /> <activity android:name=".mapsactivity" android:label="@string/title_activity_maps" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
as seen on android docs : https://developers.google.com/android/reference/com/google/android/gms/maps/googlemap.onmylocationchangelistener
googlemap.onmylocationchangelistener deprecated. tutorial using old.
from link above, able redirected newer tutorials , how-to guides (which solve setmylocationenabled error).
edit : recommended deprecated, such life in software development. if you're looking newest way of doing it, check out android documentations.
Comments
Post a Comment