Created
August 10, 2021 12:58
-
-
Save ibrajix/85ea2f575e6a68ad751bb881efab67c1 to your computer and use it in GitHub Desktop.
MapFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MapFragment : Fragment() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
} | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
// Inflate the layout for this fragment | |
var root = inflater.inflate(R.layout.fragment_map, container, false) | |
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment | |
mapFragment.getMapAsync { map-> | |
map.setOnMapClickListener { lat-> | |
//when clicked, initialize marker options | |
val markerOptions = MarkerOptions() | |
markerOptions.position(lat) | |
markerOptions.title(lat.latitude.toString() + lat.longitude.toString()) | |
//remove marker | |
map.clear() | |
//animate to zoom marker | |
map.animateCamera(CameraUpdateFactory.newLatLngZoom(lat, 10F)) | |
//ad marker on map | |
map.addMarker(markerOptions) | |
} | |
} | |
return root | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment