小编Max*_*ner的帖子

在Android地图应用中更改地图类型

我对编程很新.我正在参加一个移动开发课程,这对我来说都是新手.我在Android工作室中创建了一个非常基本的Android应用程序,它显示了标准的Google Map.我需要在应用程序上创建按钮,将地图从普通地图改为卫星地形和混合地图.我一直在这里和其他多个来源搜索,但我不知道从哪里开始,或者把我在其他网站上找到的代码放在哪里.有人可以帮忙吗?我相信这很容易,我只是不知道该怎么做.

谢谢!

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity"
    tools:ignore="MissingPrefix">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_margin="5dp"
        class="com.google.android.gms.maps.MapFragment"
        android:id="@+id/map"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        map:cameraBearing="112.5"
        map:cameraTargetLat="-33.796923"
        map:cameraTargetLng="150.922433"
        map:cameraTilt="30"
        map:cameraZoom="13"
        map:uiCompass="true"
        map:uiRotateGestures="true"
        map:uiScrollGestures="false"
        map:uiTiltGestures="true"
        map:uiZoomControls="true"
        map:uiZoomGestures="true"
     />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

.java文件

package geog498v.mymap;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapActivity extends FragmentActivity implements OnMapReadyCallback {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        MapFragment mapFragment = (MapFragment)     getFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this); …
Run Code Online (Sandbox Code Playgroud)

java android google-maps

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

google-maps ×1

java ×1