我正在使用带有登录系统的android studio创建一个谷歌地图应用程序。我的问题是地图不会放大。我只在地图上添加了一个简单的搜索栏。当我在没有登录系统的应用程序上运行相同的代码时,它可以很好地工作,但是,登录系统却没有。所以我的问题是,从下面的代码判断可能是什么原因?
我的应用级别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>
我将不胜感激任何帮助。提前谢谢!
答案 0 :(得分:0)
你应该使用有助于自动缩放纬度和经度地址的相机焦点,制作这个逻辑:
在My MapsActivity类中添加此行,您可以在地图上添加标记:
render partial: @users, layout: "homepage"
这对你有帮助,它帮助我。
答案 1 :(得分:0)
Try this
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
答案 2 :(得分:0)
try this, Add below line inside @Override onMapReady method ,
mMap.getUiSettings().setZoomControlsEnabled(true);
答案 3 :(得分:0)
If you need to zoom in map after getting latitude and longitude, you have to change this line.
from
mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
to
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng()), 13);
here 13 in the above method is zoom level of map, you can change this zoom level according to your application requirement.
and If you want to display zoom controls on google map
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
}