【发布时间】:2018-09-30 05:45:04
【问题描述】:
我有一个带有 Google 地图活动的 android 应用程序,调试版本的效果非常好,但发布版本根本无法加载地图。活动已启动,但地图未显示。
这是发布版本的 Google Maps Activity 的 SS:
有人知道怎么了?
这是活动 xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.renovaciontabasco.gouapp.UbiActivity" />
google_maps_api.xml:
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string>
还有java文件:
import android.app.Activity;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class UbiActivity extends FragmentActivity implements OnMapReadyCallback {
static double longitud;
static double latitud;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ubi);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status== ConnectionResult.SUCCESS){
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
} else {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,(Activity)getApplicationContext(),10);
dialog.show();
}
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public static void direccion(double longi, double lat){
longitud = longi;
latitud = lat;
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
UiSettings uiSettings = mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
LatLng locUniv = new LatLng(latitud,longitud);
mMap.addMarker(new MarkerOptions().position(locUniv).title("Universidad"));
float zoomlevel = 16;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(locUniv,zoomlevel));
}
}
【问题讨论】:
标签: android google-maps android-studio android-activity google-maps-api-3