[大家好,我正在为地图使用片段,我将地图密钥放在Manifest.xml中。现在,我正试图从PHP制作的后端API中获取Map API,并将其放入我的代码中,然后Map可以使用。
这是我的代码:-
布局
<fragment
android:id="@+id/fragment"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
tools:layout="@layout/dummy_map" />
ManiFest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_map_key" />
由于它是已编译的资源,因此无法动态更改strings.xml。在Android中还有其他保存数据的机制,这是一篇介绍数据存储的不错的文章。希望这对您有帮助check
这在Google API V2中是不可能的。文档提出了相同的建议,必须使用清单文件来分配API密钥: