📅  最后修改于: 2023-12-03 14:39:10.817000             🧑  作者: Mango
Android-Google Maps是针对Android平台的Google地图API。通过该API,开发人员可以在应用程序中嵌入Google地图,并添加各种自定义功能和交互。
dependencies {
implementation 'com.google.android.gms:play-services-maps:17.0.0'
}
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="API_KEY_HERE" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the MapView and get notified when the map is ready to be used.
mapView = (MapView) findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney, Australia, 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));
}
通过Android-Google Maps API,您可以将Google地图添加到您的应用程序中并为用户提供丰富的地图功能。无论您是要编写一个导航应用程序、位置搜索应用程序还是其他类型的应用程序,Android-Google Maps都可以让您快速轻松地实现地图需求。