gpt4 book ai didi

android - GoogleMap 未在真实设备上显示

转载 作者:行者123 更新时间:2023-11-29 21:04:08 26 4
gpt4 key购买 nike

问题是我向我的应用程序添加了 GoogleMap Activity ,我什至获得了 key ,但 map 只显示在模拟器中。当我在不同的设备上下载我的应用程序时, map 无法使用。我所能看到的只是一个空 View ,但带有“Google”字符串和“+-”键。我认为加载时间太长,但我认为 Wi-Fi 不能超过 10 分钟。这是我的代码:

MapsActivity.java

public class MapsActivity extends ActionBarActivity {

private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private static final LatLng TRACKTOR = new LatLng(55.1747, 61.2871);


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


LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);

// check if enabled and if not send user to the GPS settings
// Better solution would be to display a dialog and suggesting to
// go to the settings
if (!enabled) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}


// Move the camera instantly to Sydney with a zoom of 15.
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(TRACKTOR, 15));

// Zoom in, animating the camera.
mMap.animateCamera(CameraUpdateFactory.zoomIn());

// Zoom out to zoom level 10, animating with a duration of 2 seconds.
mMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

// Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(TRACKTOR) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

}

@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Log.w("MAP","is showing now!");
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
} else Log.w("MAP","is not showing!");
}
}

/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(55.1747, 61.2871)).title("Ледовая арена \"Трактор\""));
mMap.setBuildingsEnabled(true);
}
}

activity_maps.xml

<fragment 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"
android:id="@+id/map"
tools:context="com.project1.2014.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

最佳答案

发生这种情况是因为您使用了仅在通过 ADT 部署时才有效的调试 key 。

您的应用需要发布 key 才能在所有手机上运行。

你可以查看here关于发布证书

关于android - GoogleMap 未在真实设备上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25066148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com