Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – map.setmylocationenabled(true)不工作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的 Android应用中使用谷歌地图.我需要将地图重新​​定位到客户端的当前位置.我使用了以下声明 – @H_753_2@map.setmyLOCATIOnenabled(true);

这会在右上方显示一个按钮,但单击该按钮不起作用.

按钮单击侦听器:

@H_753_2@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获取代码,然后修改按钮单击侦听器以请求其他位置: @H_753_2@mMap.setOnMyLOCATIOnButtonClickListener(new GoogleMap.onMyLOCATIOnButtonClickListener() { @Override public Boolean onMyLOCATIOnButtonClick() { if (mGoogleApiClient != null) { LOCATIOnservices.FusedLOCATIOnApi.requestLOCATIOnupdates(mGoogleApiClient,mLOCATIOnrequest,this); } return false; } });

然后onLOCATIOnChanged()中的代码将重新定位摄像机位置,然后再次注册位置更新:

@Override
public 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)不工作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。