java - empty map when run code in android studio -
i have problem show map
, why show empty map
?! in images
i'll introduce code put key in file release/res/values/google_map_api.xml
, put in debug/res/values/google_map_api.xml
<resources> <string name="google_maps_key" translatable="false" templatemergestrategy="preserve"> aizasydci-------------hsik </string> </resources>
also put key in androidmanifest.xml
<meta-data android:name="com.google.android.geo.api_key" android:value="aizasydci-------------hsik" />
and code of mapactivity.java
public class mapsactivity extends appcompatactivity implements onmapreadycallback { private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); // obtain supportmapfragment , notified when map ready used. supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } @override public void onmapready(googlemap googlemap) { mmap = googlemap; // add marker in sydney , move camera latlng sydney = new latlng(-34, 151); mmap.addmarker(new markeroptions().position(sydney).title("marker in sydney")); mmap.movecamera(cameraupdatefactory.newlatlng(sydney)); } }
note: use mobile galaxy note
not emulator
of android studio.
please check permission part under manifest
<uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <uses-permission android:name="android.permission.access_coarse_location"/> <uses-permission android:name="android.permission.access_fine_location"/> <permission android:name="com.example.map.permission.maps_receive" android:protectionlevel="signature" /> <permission android:name="com.example.map.permission.maps_receive" android:protectionlevel="signature"/> <uses-permission android:name="com.example.map.permission.maps_receive"/>
Comments
Post a Comment