地图不缩放
我正在使用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>
我会感谢任何帮助。提前致谢!
回答:
您应该使用相机的焦点,这将有助于您的经度和纬度地址的自动变焦,使这个逻辑:
加入这一行中我MapsActivity类在其中添加在地图上的标记:
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(place.getLatLng(),12); googleMap.moveCamera(cu);
这会帮助你,它帮助我。
回答:
试试这个
private GoogleMap mMap; private LatLngBounds AUSTRALIA = new LatLngBounds(new LatLng(-44, 113), new LatLng(-10, 154));
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(AUSTRALIA, 13));// 13 number is zoom parameter
回答:
试试这个, 添加以下@覆盖onMapReady方法内线,
mMap.getUiSettings().setZoomControlsEnabled(true);
回答:
如果你需要在地图上放大得到的经度和纬度之后,你必须改变这条线。
从
mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
在上述方法
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng()), 13);
这里13是地图的缩放级别,您可以根据您的应用要求改变这一缩放级别。
,如果你想在谷歌地图显示缩放控制
@Override public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
}
以上是 地图不缩放 的全部内容, 来源链接: utcz.com/qa/260436.html