Add Google Maps API V2 in a fragment

前端 未结 11 1973
误落风尘
误落风尘 2020-11-29 03:00

I\'m trying to show the map from the Google Maps API V2 in fragment. I tried with the SupportMapFragment, but I can\'t get the expected output. Also I\'m a beginner on this

11条回答
  •  佛祖请我去吃肉
    2020-11-29 03:41

    If you are using android studio create google mapsactivity its default map fragment and generate your map API KEY and do your stuff......

    SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this);

    and our override method

    public void onMapReady(GoogleMap googleMap) {

       mMap = googleMap;
       LatLng map = new LatLng(lat, lon);
       mMap.addMarker(new MarkerOptions().position(map).title("your title"));
       mMap.animateCamera(CameraUpdateFactory.newLatLng(map));
       mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
    
    }
    

提交回复
热议问题