国内国外地图切换

您所在的位置:网站首页 高德在国外不能用吗 国内国外地图切换

国内国外地图切换

2024-07-12 18:49| 来源: 网络整理| 查看: 265

使用场景

如果app中需要支持国内、国外地图,则可以利用该示例,在app中同时集成高德和谷歌地图,保证国内外地图均可使用。

可以根据地图中心点在国内、外自动提示是否切换地图。

用到产品

Android 地图 SDK Android 定位 SDK Google Maps Android API

核心类/接口

接口

说明

版本

AMap

public final CameraPosition getCameraPosition()

返回可视区域的当前位置。在可视区域变换时,此返回会自己更新。

V2.0.0版本起

核心难点

1.采用TextureMapView解决mapview切换会黑一下的问题

TextureMapView和MapView的区别在于:

TextureMapView是一个TextureView而MapView是一个GLSurfaceView。

所以TextureMapView 可以和其他的GlSurfaceView(比如相机)共存不会出现穿透现象,也可以放在ViewPager中不会出现滑动黑边现象。

2.由高德地图切换到Google地图:

Javaprivate void changeToGoogleMapView() { zoom = mAmapView.getMap().getCameraPosition().zoom; latitude = mAmapView.getMap().getCameraPosition().target.latitude; longitude = mAmapView.getMap().getCameraPosition().target.longitude; mapbtn.setText("To Amap"); mIsAmapDisplay = false; mGoogleMapView = new com.google.android.gms.maps.MapView(this, new GoogleMapOptions() .camera(new com.google.android.gms.maps.model .CameraPosition(new com.google.android.gms.maps.model.LatLng(latitude, longitude), zoom, 0, 0))); mGoogleMapView.onCreate(null); mGoogleMapView.onResume(); mContainerLayout.addView(mGoogleMapView, mParams); mGoogleMapView.getMapAsync(this); handler.sendEmptyMessageDelayed(0,500); }

3.由Google地图切换到高德地图:

Javaprivate void changeToAmapView() { zoom = googlemap.getCameraPosition().zoom; latitude = googlemap.getCameraPosition().target.latitude; longitude = googlemap.getCameraPosition().target.longitude; mapbtn.setText("To Google"); mAmapView = new TextureMapView(this, new AMapOptions() .camera(new com.amap.api.maps.model.CameraPosition(new LatLng(latitude,longitude),zoom,0,0))); mAmapView.onCreate(null); mAmapView.onResume(); mContainerLayout.addView(mAmapView, mParams); mGoogleMapView.animate() .alpha(0f).setDuration(500).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mGoogleMapView.setVisibility(View.GONE); mContainerLayout.removeView(mGoogleMapView); if (mGoogleMapView != null) { mGoogleMapView.onDestroy(); } } }); mAmapView.getMap().setOnCameraChangeListener(this); mIsAmapDisplay = true; }

注意:手机必须已经安装了谷歌地图服务,才能保证中心点到达国外时展示谷歌地图的效果。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3