map.setmylocationenabled(true);
这会在右上方显示一个按钮,但单击该按钮不起作用.
按钮单击侦听器:
mMap.setonMyLocationbuttonClickListener(new GoogleMap.OnMyLocationbuttonClickListener() { @OverrIDe public boolean onMyLocationbuttonClick() { mMap.addMarker(new MarkerOptions().position(myLatLng).Title("My Location")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLatLng,zoomLevel)); return false; } });解决方法 只需从 my other answer here获取代码,然后修改按钮单击侦听器以请求其他位置:
mMap.setonMyLocationbuttonClickListener(new GoogleMap.OnMyLocationbuttonClickListener() { @OverrIDe public boolean onMyLocationbuttonClick() { if (mGoogleapiclient != null) { LocationServices.FusedLocationAPI.requestLocationUpdates(mGoogleapiclient,mLocationRequest,this); } return false; } });
然后onLocationChanged()中的代码将重新定位摄像机位置,然后再次注册位置更新:
@OverrIDepublic voID onLocationChanged(Location location){ mLastLocation = location; if (mCurrLocationMarker != null) { mCurrLocationMarker.remove(); } //Place current location marker LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude()); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.Title("Current position"); markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_magenta)); mCurrLocationMarker = mGoogleMap.addMarker(markerOptions); //move map camera mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(11)); if (mGoogleapiclient != null) { LocationServices.FusedLocationAPI.removeLocationUpdates(mGoogleapiclient,this); }}总结
以上是内存溢出为你收集整理的android – map.setmylocationenabled(true)不工作全部内容,希望文章能够帮你解决android – map.setmylocationenabled(true)不工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)