当前位置: 首页 > 知识库问答 >
问题:

Android在SplashScreen后使用Google Maps显示主要活动

邵兴文
2023-03-14
    package me.resq.resqme;

    import android.app.Activity;
    import android.os.Bundle;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MainActivity extends Activity {

// Constant for defining latitude and longitude
static final LatLng DerekPos = new LatLng(40 , -79);

// GoogleMap class
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // verify we can interact with the Google Map
    try {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().
                    findFragmentById(R.id.map)).getMap();
        }
        // Show a satellite map with roads
        /* MAP_TYPE_NORMAL: Basic map with roads.
        MAP_TYPE_SATELLITE: Satellite view with roads.
        MAP_TYPE_TERRAIN: Terrain view without roads.
        */
        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        // Place dot on current location
        googleMap.setMyLocationEnabled(true);

        // Turns traffic layer on
        googleMap.setTrafficEnabled(true);

        // Enables indoor maps
        googleMap.setIndoorEnabled(true);

        // Turns on 3D buildings
        googleMap.setBuildingsEnabled(true);

        // Show Zoom buttons
        googleMap.getUiSettings().setZoomControlsEnabled(true);

        // Create a marker in the map at a given position with a title
        Marker marker = googleMap.addMarker(new MarkerOptions().
                position(DerekPos).title("Sie sind hier!"));

    } catch (Exception e) {
        e.printStackTrace();
    }

}

    }
     package me.resq.resqme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

private static int SPLASH_SCREEN_DELAY = 3000;

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

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // Executed after timer is finished (Opens MainActivity)
            Intent intent = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(intent);

            // Kills this Activity
            finish();
        }
    }, SPLASH_SCREEN_DELAY);
}
}
    <fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:layout_weight="0.7"
    android:layout_above="@+id/button"
    android:layout_alignParentTop="true" />

暂时还没有答案

 类似资料: