Android中的Google地图集成未显示地图

时间:2017-07-23 06:36:13

标签: android google-maps-android-api-2

我在Android的谷歌地图集成中存在问题, 当我创建一个地图活动,然后集成到谷歌API获得灰色背景,但当我创建一个新项目,然后将新项目集成到谷歌地图,将完美地工作, 我的实际项目无法集成到谷歌地图,任何人都可以帮助我, 我的意思是地图中的问题如何解决它。

public class MapViewActivity extends FragmentActivity implements OnMapReadyCallback{

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_view);
    // 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));
}

}

这是我mapactivity的代码。

1 个答案:

答案 0 :(得分:0)

确保您的API密钥在gradle.properties中设置属性。

此密钥在build.gradle中检索。

以下是使用app。{/ p>的Google Map integration的确切实现

完整的应用及其带有屏幕截图的代码可以访问github

Note:在MapsMarkerActivity的onCreate中,我确实使用了Geocoder,它填充了给定城市或默认城市的经度和纬度。