Android Google Mapview Activity not opening in Android Studio

落爺英雄遲暮 提交于 2019-12-01 21:06:55

Your activity creates the layout, but you need some additional code to actually start the map:

In MapsActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    MapFragment mapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

Also, your activity should implement OnMapReadyCallback for more map logic. See the documentation at https://developers.google.com/maps/documentation/android/

After a couple of days of trying all the stuff, I created another project with MapActivity. I followed just the instructions in the google-mp-api.xml that came with the MapActivity. With that, I created new Google Maps credentials and API Key for the App. I replaced that and everything worked. All dependencies, google play services everything was automatically working. The Map with the marker on (0,0) was setup. This works effortlessly. John D's pointer to revisit the API key requirements was useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!