高德地图 Locationactivitymanagerproxyy为什么引用不到

&&国之画&&&&&&
版权所有 京ICP备号-2
迷上了代码!融云&高德地图-实现地理位置发送
1:注册高德地图开发者账号,创建应用、获取高德地图的 appkey
2: jar 包建议直接从 融云 demo 中拷贝。因为某地图厂商的版本兼容做的不好。可能你下载的新版本的 jar
在老版本的实现代码中就找不到这个接口。或者那个接口变动了
Click LocationMessage:
1:注册高德地图开发者账号,创建应用、获取高德地图的 appkey
2: jar 包建议直接从 融云 demo 中拷贝。因为某地图厂商的版本兼容做的不好。可能你下载的新版本的 jar. 在老版本的实现代码中就找不到这个接口。或者那个接口变动了
3: 参考 demo 代码 在 RongCloudEvent.java 上实现了 地理位置提供者接口 。 onStartLocation 方法中点击开启 地图的 Activity
public void onStartLocation(Context context, LocationCallback locationCallback) {
* demo 代码
开发者需替换成自己的代码。
DemoContext.getInstance().setLastLocationCallback(locationCallback);
Intent intent = new Intent(context, AMAPLocationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
AMAPLocationActivity 为核心逻辑类。高德地图的展示 获取经纬度和定位的逻辑全在此处
public class AMAPLocationActivity extends ActionBarActivity implements View.OnClickListener, LocationSource, GeocodeSearch.OnGeocodeSearchListener, AMapLocationListener, AMap.OnCameraChangeListener {
private MapView mapV
private AMap aM
private LocationManagerProxy mLocationManagerP
private Handler handler = new Handler();
private LocationSource.OnLocationChangedL
private LatLng myLocation =
private Marker centerM
private boolean isMovingMarker =
private BitmapDescriptor successD
private GeocodeSearch geocodeS
private LocationMessage mM
private TextView tvCurL
private boolean model =
private boolean isP
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_amap);
getSupportActionBar().setTitle("地理位置");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.de_actionbar_back);
mapView = (MapView) findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
initAmap();
setUpLocationStyle();
private void initAmap() {
if (aMap == null) {
aMap = mapView.getMap();
if (getIntent().hasExtra("location")) {
isPerview =
mMsg = getIntent().getParcelableExtra("location");
tvCurLocation.setVisibility(View.GONE);
returns.setVisibility(View.GONE);
if (model) {
CameraPosition location = new CameraPosition.Builder()
.target(new LatLng(mMsg.getLat(), mMsg.getLng())).zoom(18).bearing(0).tilt(30).build();
show(location);
aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
.position(new LatLng(mMsg.getLat(), mMsg.getLng())).title(mMsg.getPoi())
.snippet(mMsg.getLat() + "," + mMsg.getLng()).draggable(false));
aMap.setLocationSource(this);// 设置定位监听
aMap.setMyLocationEnabled(true);
aMap.getUiSettings().setZoomControlsEnabled(false);
aMap.getUiSettings().setMyLocationButtonEnabled(false);
CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(15);//设置缩放监听
aMap.moveCamera(cameraUpdate);
successDescripter = BitmapDescriptorFactory.fromResource(R.drawable.icon_usecarnow_position_succeed);
geocodeSearch = new GeocodeSearch(this);
geocodeSearch.setOnGeocodeSearchListener(this);
private static final String MAP_FRAGMENT_TAG = "map";
private SupportMapFragment aMapF
private void show(CameraPosition location) {
AMapOptions aOptions = new AMapOptions();
aOptions.zoomGesturesEnabled(true);
aOptions.scrollGesturesEnabled(false);
aOptions.camera(location);
if (aMapFragment == null) {
aMapFragment = SupportMapFragment.newInstance(aOptions);
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.add(android.R.id.content, aMapFragment,
MAP_FRAGMENT_TAG);
private ImageV
private void initUI() {
returns = (ImageView) findViewById(R.id.myLocation);
returns.setOnClickListener(this);
tvCurLocation = (TextView) findViewById(R.id.location);
public void onClick(View v) {
switch (v.getId()) {
case R.id.myLocation:
CameraUpdate update = CameraUpdateFactory.changeLatLng(myLocation);
aMap.animateCamera(update);
public void activate(OnLocationChangedListener onLocationChangedListener) {
listener = onLocationChangedL
mLocationManagerProxy = LocationManagerProxy.getInstance(this);
mLocationManagerProxy.requestLocationData(
LocationProviderProxy.AMapNetwork, -1, 100, this);
public void deactivate() {
if (mLocationManagerProxy != null) {
mLocationManagerProxy.removeUpdates(this);
mLocationManagerProxy.destroy();
mLocationManagerProxy =
public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
if (i == 0) {
if (regeocodeResult != null && regeocodeResult.getRegeocodeAddress() != null) {
endAnim();
centerMarker.setIcon(successDescripter);
RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress();
String formatAddress = regeocodeResult.getRegeocodeAddress().getFormatAddress();
String shortAdd = formatAddress.replace(regeocodeAddress.getProvince(), "").replace(regeocodeAddress.getCity(), "").replace(regeocodeAddress.getDistrict(), "");
tvCurLocation.setText(shortAdd);
double latitude = regeocodeResult.getRegeocodeQuery().getPoint().getLatitude();
double longitude = regeocodeResult.getRegeocodeQuery().getPoint().getLongitude();
mMsg = LocationMessage.obtain(latitude, longitude, shortAdd, getMapUrl(latitude, longitude));
NLog.e("LocationChange", shortAdd + latitude + "----" + longitude);
NToast.shortToast(AMAPLocationActivity.this, "没有搜索到结果");
NToast.shortToast(AMAPLocationActivity.this, "搜索失败,请检查网络");
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null && aMapLocation.getAMapException().getErrorCode() == 0) {
if (listener != null) {
listener.onLocationChanged(aMapLocation);// 显示系统小蓝点
myLocation = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());//获取当前位置经纬度
tvCurLocation.setText(aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName());//当前位置信息
double latitude = aMapLocation.getLatitude();
double longitude = aMapLocation.getLongitude();
mMsg = LocationMessage.obtain(latitude, longitude, aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName(), getMapUrl(latitude, longitude));
NLog.e("LocationInit", aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName() + latitude + "----" + longitude);
addChooseMarker();
private void addChooseMarker() {
//加入自定义标签
MarkerOptions centerMarkerOption = new MarkerOptions().position(myLocation).icon(successDescripter);
centerMarker = aMap.addMarker(centerMarkerOption);
centerMarker.setPositionByPixels(mapView.getWidth() / 2, mapView.getHeight() / 2);
handler.postDelayed(new Runnable() {
public void run() {
CameraUpdate update = CameraUpdateFactory.zoomTo(17f);
aMap.animateCamera(update, 1000, new AMap.CancelableCallback() {
public void onFinish() {
aMap.setOnCameraChangeListener(AMAPLocationActivity.this);
public void onCancel() {
private void setMovingMarker() {
if (isMovingMarker)
isMovingMarker =
centerMarker.setIcon(successDescripter);
hideLocationView();
public void onCameraChange(CameraPosition cameraPosition) {
if (centerMarker != null) {
setMovingMarker();
public void onCameraChangeFinish(CameraPosition cameraPosition) {
LatLonPoint point = new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude);
RegeocodeQuery query = new RegeocodeQuery(point, 50, GeocodeSearch.AMAP);
geocodeSearch.getFromLocationAsyn(query);
if (centerMarker != null) {
animMarker();
showLocationView();
public void onLocationChanged(Location location) {
public void onStatusChanged(String provider, int status, Bundle extras) {
public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {
protected void onResume() {
super.onResume();
mapView.onResume();
protected void onPause() {
super.onPause();
mapView.onPause();
deactivate();
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
protected void onDestroy() {
mapView.onDestroy();
super.onDestroy();
private ValueAnimator animator =
private void animMarker() {
isMovingMarker =
if (animator != null) {
animator.start();
animator = ValueAnimator.ofFloat(mapView.getHeight() / 2, mapView.getHeight() / 2 - 30);
animator.setInterpolator(new DecelerateInterpolator());
animator.setDuration(150);
animator.setRepeatCount(1);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
centerMarker.setPositionByPixels(mapView.getWidth() / 2, Math.round(value));
animator.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
centerMarker.setIcon(successDescripter);
animator.start();
private void endAnim() {
if (animator != null && animator.isRunning())
animator.end();
private void hideLocationView() {
ObjectAnimator animLocation = ObjectAnimator.ofFloat(tvCurLocation, "TranslationY", -tvCurLocation.getHeight() * 2);
animLocation.setDuration(200);
animLocation.start();
private void showLocationView() {
ObjectAnimator animLocation = ObjectAnimator.ofFloat(tvCurLocation, "TranslationY", 0);
animLocation.setDuration(200);
animLocation.start();
private void setUpLocationStyle() {
// 自定义系统定位蓝点
MyLocationStyle myLocationStyle = new MyLocationStyle();
myLocationStyle.myLocationIcon(BitmapDescriptorFactory.
fromResource(R.drawable.img_location_now));
myLocationStyle.strokeWidth(0);
myLocationStyle.strokeColor(R.color.main_theme_color);
myLocationStyle.radiusFillColor(Color.TRANSPARENT);
aMap.setMyLocationStyle(myLocationStyle);
private Uri getMapUrl(double x, double y) {
String url = "/v3/staticmap?location=" + y + "," + x +
"&zoom=17&scale=2&size=150*150&markers=mid,,A:" + y + ","
+ x + "&key=" + "ee95e52bfbcfbcf21df0";
NLog.e("getMapUrl", url);
return Uri.parse(url);
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.de_location_menu, menu);
if (isPerview) {
menu.getItem(0).setVisible(false);
return super.onCreateOptionsMenu(menu);
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.send_location:
if (mMsg != null) {
DemoContext.getInstance().getLastLocationCallback().onSuccess(mMsg);
DemoContext.getInstance().setLastLocationCallback(null);
DemoContext.getInstance().getLastLocationCallback()
.onFailure("定位失败");
case android.R.id.home:
return super.onOptionsItemSelected(item);
&framelayout android:layout_height="match_parent" android:layout_width="match_parent"&
&/framelayout&
将代码拷贝 和 相关资源文件拷贝以后就能实现。下面对代码逻辑做一下介绍
代码整体分两部分 一部分是发送位置逻辑 一部分是从会话界面地理位置消息点击进来逻辑。主要逻辑是 发送位置逻辑
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null && aMapLocation.getAMapException().getErrorCode() == 0) {
如果卡在这个 if 判断没有进来那说明你配置的高德相关的 jar 、key 、storeFile(此处在 gradle 配置) 配置高德环境有问题。此处具体咨询高德地图
另外需要值得注意的一点是获取静态缩略图的问题
private Uri getMapUrl(double x, double y) {
String url = "/v3/staticmap?location=" + y + "," + x +
"&zoom=17&scale=2&size=150*150&markers=mid,,A:" + y + ","
+ x + "&key=" + "ee95e52bfbcfbcf21df0";
NLog.e("getMapUrl", url);
return Uri.parse(url);
最后组拼的 key.在高德官网解释是说需要配置自己的 高德key.这里是个坑,我拿着自己的 key 去中解析 返回错误码 10009
当时给愁坏了。后来朋友提示随意拿个别人的 key 绑定了 web api 的去使用试试。结果还真行。所以在此处参考博文的小伙伴直接用上面 demo 提供的 key 即可。
点击地理位置消息预览的逻辑 在 RongCloudEvent.java 重写消息点击事件
if (message.getContent() instanceof LocationMessage) {
Intent intent = new Intent(context, AMAPLocationActivity.class);
intent.putExtra("location", message.getContent());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
在 AMAPLocationActivity 截取并且判断这个 intent
if (getIntent().hasExtra("location")) {
isPerview =
mMsg = getIntent().getParcelableExtra("location");
tvCurLocation.setVisibility(View.GONE);
returns.setVisibility(View.GONE);
if (model) {
CameraPosition location = new CameraPosition.Builder()
.target(new LatLng(mMsg.getLat(), mMsg.getLng())).zoom(18).bearing(0).tilt(30).build();
show(location);
aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
.position(new LatLng(mMsg.getLat(), mMsg.getLng())).title(mMsg.getPoi())
.snippet(mMsg.getLat() + "," + mMsg.getLng()).draggable(false));
最后的 return 不继续执行代码。完成当前位置的预览即结束
发送地理位置&高德地图结束 有任何疑问可以在下方留言。高德地图相关的问题可登陆高德地图官网进行咨询高德地图 LocationManagerProxy为什么引用不到啊
[问题点数:40分]
高德地图 LocationManagerProxy为什么引用不到啊
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2016年4月 移动开发大版内专家分月排行榜第二
2015年12月 移动开发大版内专家分月排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。&&国之画&&&&&&
版权所有 京ICP备号-2
迷上了代码!问题:高德地图混淆代码后定位失败
描述:android高德地图android&studio编译
因为在我的工程里出现了这种情况。不混淆代码可以,一旦混淆代码后,定位那部分的方法虽然可以调用,但一直是定位失败,随后我下了其官方的demo,混码编译之后也是如此,有人知道怎么解决吗?
我的用的是android&studio
下面是我代码混淆的编码-keep&class&com.nostra13.universalimageloader.**&{&*;&}
-dontwarn&com.pgyersdk.**
-dontwarn&com.viewpagerindicator.**
-dontwarn&com.handmark.pulltorefresh.library.**
-dontwarn&com.gc.materialdesign.**
-dontwarn&org.apache.**
-dontwarn&org.apache.http.**
-dontwarn&mons.**
-keep&class&com.pgyersdk.**&{&*;&}
-keep&class&org.apache.http.**&{*;}
-keep&class&com.viewpagerindicator.**&{*;}
-keep&class&com.handmark.pulltorefresh.library.**&{*;}
-keep&class&com.gc.materialdesign.**&{*;}
-dontwarn&com.amap.api.**
-dontwarn&com.aps.**
-dontwarn&android.support.v4.**
&-keep&class&android.support.v4.**
&-keep&interface&android.support.v4.app.**&{*;}
-dontwarn&com.a.a.**
-dontwarn&com.autonavi.**
#高德相关混淆文件
-keep&&&class&com.amap.api.location.**{*;}
-keep&&&class&com.aps.**{*;}
-keep&&&class&com.amap.api.services.**{*;}
下面是我调用定位的方法
mLocationManagerProxy&=&LocationManagerProxy.getInstance(this);
&&&&&&&&mLocationManagerProxy.setGpsEnable(false);
&&&&&&&&mLocationManagerProxy.requestLocationData(
&&&&&&&&&&&&&&&&LocationProviderProxy.AMapNetwork,&-1,&15,&this);
以上介绍了“高德地图混淆代码后定位失败”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:/itwd/652831.html
上一篇: 下一篇:

我要回帖

更多关于 sdk manager proxy 的文章

 

随机推荐