本文介绍了Google地图不显示Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将逻辑添加到片段或活动中。 将地图片段元素添加到图层。 > 获取API密钥(您可能需要将密钥与您的调试版本和应用的签名版本相关联,每个人都有不同的签名,但两者都可以共享相同的密钥)。 > 配置应用程序清单。在这里,要使用谷歌地图,您需要:互联网访问,Open GL规范,如果地图将存储在本地,您需要访问设备存储,因为地图库作为Google Play服务的一部分包含在内,因此您需要 Add logic to the Fragment or Activity.
Add the map fragment element to the layer.
Obtain an API Key (you probably need to associate the key to your debug version and your signed version of the app, everyone will have a different signature but both can share the same key).
Configure the application manifest. Here, to use Google Maps you will need: Internet Access, Open GL specifications, if the map will be stored locally you sill need access to the device storage too, as the map libraries are included as part of the google play services you need to configure this too.
我想在我的应用程序中实施Google地图。我添加了Google地图活动并创建了一个密钥。我没有在其他地方的代码中改变任何东西。
MapsActivity
public类MapsActivity扩展FragmentActivity实现OnMapReadyCallback { 私有GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); //获取SupportMapFragment并在地图准备好使用时得到通知。 SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } / ** *操作一次可用的地图。 *当地图准备好使用时,会触发此回调。 *这是我们可以添加标记或线条,添加听众或移动相机的位置。在这种情况下, *我们只在澳大利亚悉尼附近添加一个标记。 *如果设备上未安装Google Play服务,系统会提示用户在SupportMapFragment中安装 * it。只有当用户安装了 * Google Play服务并返回到应用时,才会触发此方法。 * / @Override public void onMapReady(GoogleMap googleMap){ mMap = googleMap; //在悉尼添加一个标记并移动相机 LatLng sydney = new LatLng(-34,151); mMap.addMarker(new MarkerOptions()。position(sydney).title(Marker in Sydney)); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); }}
activity_maps.xml
< fragment xmlns:android =schemas.android/apk/res/android xmlns:map =schemas.android/apk/res-auto xmlns:tools =schemas.android/tools android:id =@ + id / map android:name =com.google.android.gms.maps.SupportMapFragment android:layout_width =match_parent android: layout_height =match_parent tools:context =com.example.kevin.map.MapsActivity/>解决方案
要使用Google地图,您必须:
在清单级别:
<! - 如果您要使用此位置的位置 - > < uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/> < uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/> <! - Maps API需要OpenGL ES 2.0。 - > < uses-feature android:glEsVersion =0x00020000 android:required =true/> < uses-permission android:name =com.example.permission.MAPS_RECEIVE/> < uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>在清单中的应用程序级别:
< meta-data android:name =com.google.android.gms.version android:value =@ integer / google_play_services_version/> < meta-data android:name =com.google.android.maps.v2.API_KEY android:value =< YOUR MAP API KEY> />
I want to implement google maps in mine app. I added a google maps activity and created a key. I didn't change anything in the code elsewhere. I should work but it doesn't.
MapsActivity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); }}
activity_maps.xml
<fragment xmlns:android="schemas.android/apk/res/android" xmlns:map="schemas.android/apk/res-auto" xmlns:tools="schemas.android/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.kevin.map.MapsActivity" />解决方案
To work with Google Maps you must:
At the manifest level:
<!-- Location if you will use this --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- Maps API needs OpenGL ES 2.0. --> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="com.example.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
At the application level inside the manifest:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="<YOUR MAP API KEY>" />
更多推荐
Google地图不显示Android
发布评论