我正在使用android studio创建一个带有登录系统的Google地图应用程序。我遇到的问题是地图不能放大。我只在地图上添加了一个简单的搜索栏。当我在没有登录系统的应用程序上运行相同的代码时,它完美地工作,但是,登录系统没有。所以我的问题是,从下面的代码判断可能是什么原因?地图不缩放
我的应用程序级的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.mongodb.stitch.examples.mongorestaurant"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/json-simple-1.1.1.jar')
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.google.android.gms:play-services-location:10.2.1'
compile 'com.google.android.gms:play-services-places:10.2.1'
compile 'org.mongodb:stitch:0.1.0-SNAPSHOT'
compile 'com.google.code.gson:gson:2.8.2'
testCompile 'junit:junit:4.12'
}
repositories {
// TODO: Remove once BSON 3.5.0 is released
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
我MapsActivity.java
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
PlaceAutocompleteFragment placeAutoComplete;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
placeAutoComplete = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete);
placeAutoComplete.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.d("Maps", "Place selected: " + place.getName());
mMap.addMarker(new MarkerOptions().position(place.getLatLng())
.title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
}
@Override
public void onError(Status status) {
Log.d("Maps", "An error occurred: " + status);
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}
我activity_maps.xml
<LinearLayout 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=".MapsActivity"
android:orientation="vertical"
android:weightSum="1">
<fragment
android:id="@+id/place_autocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
而我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mongodb.stitch.examples.mongorestaurant">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MapsActivity" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我会感谢任何帮助。提前致谢!
你需要给我们更多的信息,例如代码中您怀疑问题的地方。地图不缩放,但它甚至可以正确加载?换句话说,缩放真的是问题,而不是比这更重要的东西? –
@TimBiegeleisen,是的,你说得对,当我在另一张地图上运行应用程序时,地图的一大块内容甚至没有载入。我怀疑这是因为我的登录系统或我已经提供给10.2.1的播放服务的版本。这个问题可能是因为我的登录系统中的编程不佳而影响了地图吗?感谢帮助。 – Ruben