zoukankan      html  css  js  c++  java
  • 谷歌地图集成步骤

    1.首先要去google官网注册开发者账号,并申请key

    2.导入依赖包

    • compile 'com.google.android.gms:play-services-maps:10.2.4'

    3.使用Android Studio安装Google Play Services

    4.​在布局文件中添加如下代码

    <fragment
    	android:id="@+id/fm_google_map"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    

    5.将申请的key配置到清单文件的application节点中

    <meta-data
    	android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_map_key" />
    

    6.在Activity的onCreate方法中添加如下代码

    mGoogleMap = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fm_google_map);
    mGoogleMap.getMapAsync(this);
    

    7.重写onMapReady方法

    @Override
    public void onMapReady(GoogleMap googleMap) {
      LatLng sydney = new LatLng(-34, 151);
      googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
      googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
    

    8.此时运行程序,会发现有如下效果

  • 相关阅读:
    hdu 1978 How many ways
    hdu 2209 翻纸牌游戏
    hdu 2149 Public Sale (博弈规律题)
    CF 353C Find Maximum #205 (Div. 2)
    barrier and Fence
    window coordinate
    GPU hang
    the application was unable to start correctly 0xc000007b
    vertex buffer 数据结构 如何读vb的memory pool
    map
  • 原文地址:https://www.cnblogs.com/coderwjq/p/6857760.html
Copyright © 2011-2022 走看看