Android 谷歌地图缩放功能不工作
目前我正在我的项目中使用谷歌地图。 我使用下面的API版本和谷歌地图显示Android 谷歌地图缩放功能不工作,android,google-maps,google-play-services,Android,Google Maps,Google Play Services,目前我正在我的项目中使用谷歌地图。 我使用下面的API版本和谷歌地图显示 android.gms:play-services-maps:9.0.2 android.gms:play-services-location:9.0.2 问题: @Override public void onMapReady(GoogleMap googleMap) { //googleMap.getUiSettings().setZoomControlsEnabled(true); mMap =
android.gms:play-services-maps:9.0.2
android.gms:play-services-location:9.0.2
问题:
@Override
public void onMapReady(GoogleMap googleMap) {
//googleMap.getUiSettings().setZoomControlsEnabled(true);
mMap = googleMap;
Log.i(TAG, "onMapReady");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this,"Please enable GPS location on your phone",Toast.LENGTH_SHORT).show();
return;
}
Log.i(TAG, "my location enabled");
mMap.setMyLocationEnabled(true);
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
buildGoogleApiClient();
if (mMap == null) {
return;
}
/* currentLatLng= new LatLng (currentLocationLatitude,currentLocationLongitude);
Log.i(TAG,"inside onMapready --->");*/
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
当我尝试在触摸屏上缩放地图时,谷歌地图不会缩放和缩放
我也无法移动地图查看其他位置
这是我的代码:
@Override
public void onMapReady(GoogleMap googleMap) {
//googleMap.getUiSettings().setZoomControlsEnabled(true);
mMap = googleMap;
Log.i(TAG, "onMapReady");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this,"Please enable GPS location on your phone",Toast.LENGTH_SHORT).show();
return;
}
Log.i(TAG, "my location enabled");
mMap.setMyLocationEnabled(true);
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
buildGoogleApiClient();
if (mMap == null) {
return;
}
/* currentLatLng= new LatLng (currentLocationLatitude,currentLocationLongitude);
Log.i(TAG,"inside onMapready --->");*/
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
*包含XML文件*
这是我用来显示谷歌地图的xml布局文件
<RelativeLayout 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:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment 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.mega.hertz.seeky.MainActivity"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:paddingBottom="@dimen/vertical_page_margin"
android:paddingLeft="@dimen/horizontal_page_margin"
android:paddingRight="@dimen/horizontal_page_margin"
android:paddingTop="@dimen/margin_small">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="50dp">
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
在代码中添加以下函数
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(latLng).title("My Location"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(20));
}
只需在滚动视图的底部添加片段。因为您的地图片段与ScrollView重叠。 更改您的xml格式,如:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
<fragment 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.mega.hertz.seeky.MainActivity"/>
在此处共享您的XML文件HI,我已经包括了xml文件。这个解决方案在地图加载时将地图移动到缩放级别。我的问题是,当我缩放地图时,谷歌地图加载后,它不工作,而且我不能移动地图。基本上,地图上的手指触摸不工作。当我在滚动视图后放入谷歌地图的片段,编译代码并检查Ui时,PlaceAutoCompleteFragment google搜索place没有出现,只有google地图出现,但我可以缩放。我需要谷歌地方搜索使用片段PlaveAutoFragment请分享您的代码为“PlaceAutocompleteFragment”。你也可以参考这个链接:谢谢。我的代码是PlaceAutocompleteFragment autocompleteFragment=(PlaceAutocompleteFragment)getFragmentManager();autocompleteFragment.setOnPlaceSelectedListener(此);((EditText)autocompleteFragment.getView().findViewById(R.id.place\u autocomplete\u search\u input)).setTextSize(15.0f);只需在xml文件中设置ScrollView height=“wrap_content”。并将滚动视图放在片段之后。和你上传的xml文件一样,还有你的问题。这样你们就可以在地图上缩放,也可以找到地方。谢谢。你的意思是在地图片段后滚动查看。显示它