android - PlacePicker does not launch with location -
i working on project api google place. use placepicker , track phone launch placepicker am. class location , placepicker.
public class prospectionactivity extends baseactivity { private static final int place_picker_request = 1; private textview mname; private textview maddress; private textview mattributions; private static final latlngbounds bounds_mountain_view = new latlngbounds( new latlng(48.8453849, 2.328134900000009), new latlng(48.866667, 2.333333)); public double latitude; public double longitude; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); framelayout contentframelayout = (framelayout) findviewbyid(r.id.content_frame); //remember framelayout area within activity_base.xml getlayoutinflater().inflate(r.layout.activity_prospection, contentframelayout); locationmanager service = (locationmanager) getsystemservice(location_service); boolean enabled = service .isproviderenabled(locationmanager.gps_provider); if (!enabled) { intent intent = new intent(settings.action_location_source_settings); startactivity(intent); } locationmanager lm = (locationmanager)getsystemservice(context.location_service); location location = lm.getlastknownlocation(locationmanager.gps_provider); if (location!=null){ longitude = location.getlongitude(); latitude = location.getlatitude(); final latlngbounds coordinate = new latlngbounds(new latlng(latitude-0.000005, longitude-0.000005),new latlng(latitude+0.000005,longitude+0.000005)); mname = (textview) findviewbyid(r.id.textview); maddress = (textview) findviewbyid(r.id.textview2); mattributions = (textview) findviewbyid(r.id.textview3); button pickerbutton = (button) findviewbyid(r.id.pickerbutton); pickerbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { try { placepicker.intentbuilder intentbuilder = new placepicker.intentbuilder(); intentbuilder.setlatlngbounds(coordinate); intent intent = intentbuilder.build(prospectionactivity.this); startactivityforresult(intent, place_picker_request); } catch (googleplayservicesrepairableexception | googleplayservicesnotavailableexception e) { e.printstacktrace(); } } }); } } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == place_picker_request && resultcode == activity.result_ok) { final place place = placepicker.getplace(this, data); final charsequence name = place.getname(); final charsequence address = place.getaddress(); string attributions = (string) place.getattributions(); if (attributions == null) { attributions = ""; } mname.settext(name); maddress.settext(address); mattributions.settext(html.fromhtml(attributions)); } else { super.onactivityresult(requestcode, resultcode, data); } }
} `
unfortunately, when click on button launch placepicker. nothing happens. if can me please.
here manifest
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".baseactivity" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar" /> <activity android:name=".prospectionactivity" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <meta-data android:name="com.google.android.geo.api_key" android:value="aizasyafovxbfhflmqegopanionahiyar9jvkrk" /> </application>
it might useful in logcat output errors tell what's going on.
looking @ manifest see haven't requested access_fine_location permission. might problem. try adding:
<uses-permission android:name="android.permission.access_fine_location" />
Comments
Post a Comment