高德地图中心点以及自定义infowindow

高德地图中心点以及自定义infowindow,第1张

二,初始化布局的引用

三,自定义的marker设置

重写地图加载完毕的方法,在地图加载完毕之后调用添加marker

四,展示InfoWindow

需要给infowindow设置监听

实现监听后,重写以下方法

五,关于中心点移动获取地点

先要实现监听

书写监听后,重写监听方法

六,逆向地理编码对象初始化

设置监听后,重写方法

以上基本就是关于地图的一些设置, 有关于地图的配置什么的, 请自行阅读高德官方api。

博客地址: https://blog.csdn.net/binbinxiaoz

使用swift来使用高德地图,这里使用Android实践高德地图包含定位,移动地图动画,获取网络数据,marker标记以及点击,Infowindow自定义界面以及点击,以及点击无marker地图上面隐藏infowindow等功能。直接看代码

[java] view plain copy print?

package com.carmap.ui

import android.graphics.Color

import android.location.Location

import android.os.Bundle

import android.util.Log

import android.view.View

import android.view.View.OnClickListener

import android.view.animation.Animation

import android.view.animation.Animation.AnimationListener

import android.view.animation.AnimationUtils

import android.widget.ImageView

import com.amap.api.location.AMapLocation

import com.amap.api.location.AMapLocationListener

import com.amap.api.location.LocationManagerProxy

import com.amap.api.location.LocationProviderProxy

import com.amap.api.maps.AMap

import com.amap.api.maps.AMap.InfoWindowAdapter

import com.amap.api.maps.AMap.OnCameraChangeListener

import com.amap.api.maps.AMap.OnInfoWindowClickListener

import com.amap.api.maps.AMap.OnMapClickListener

import com.amap.api.maps.AMap.OnMapLoadedListener

import com.amap.api.maps.AMap.OnMarkerClickListener

import com.amap.api.maps.CameraUpdateFactory

import com.amap.api.maps.LocationSource

import com.amap.api.maps.MapView

import com.amap.api.maps.UiSettings

import com.amap.api.maps.model.BitmapDescriptorFactory

import com.amap.api.maps.model.CameraPosition

import com.amap.api.maps.model.LatLng

import com.amap.api.maps.model.Marker

import com.amap.api.maps.model.MarkerOptions

import com.amap.api.maps.model.MyLocationStyle

import com.carmap.R

import com.carmap.ui.base.BaseActivity

/**

*

* @author jwzhangjie

*

*/

public class MapActivity extends BaseActivity implements AMapLocationListener,

LocationSource, OnMarkerClickListener, OnInfoWindowClickListener,

InfoWindowAdapter, OnMapLoadedListener, OnCameraChangeListener,

AnimationListener, OnClickListener, OnMapClickListener {

private MapView mapView

private AMap aMap

private LocationManagerProxy aMapManager

private OnLocationChangedListener mListener

private UiSettings mUiSettings

private AMapLocation aLocation

private Animation centerMarker

private ImageView centerImageView

private Marker currentMarker

private boolean isFirst = true

private ImageView locate

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_map)

mapView = (MapView) findViewById(R.id.mapView)

mapView.onCreate(savedInstanceState)// 此方法必须重写

centerMarker = AnimationUtils.loadAnimation(this,

R.anim.center_map_bounds)

centerImageView = (ImageView) findViewById(R.id.centerMarkerImg)

locate = (ImageView) findViewById(R.id.locate)

initMap()

}

/**

* 初始化AMap对象

*/

private void initMap() {

if (aMap == null) {

aMap = mapView.getMap()

mUiSettings = aMap.getUiSettings()

}

// 自定义系统定位小蓝点

MyLocationStyle myLocationStyle = new MyLocationStyle()

myLocationStyle.myLocationIcon(BitmapDescriptorFactory

.fromResource(R.drawable.transdrawable))// 设置小蓝点的图标

myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0))// 设置圆形的边框颜色

myLocationStyle.radiusFillColor(Color.argb(0, 0, 0, 0))// 设置圆形的填充颜色

myLocationStyle.strokeWidth(0f)// 设置圆形的边框粗细

aMap.setMyLocationStyle(myLocationStyle)

aMap.setMyLocationRotateAngle(180)

aMap.setLocationSource(this)// 设置定位监听

mUiSettings.setMyLocationButtonEnabled(false)// 是否显示默认的定位按钮

aMap.setMyLocationEnabled(true)// 是否可触发定位并显示定位层

aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE)

mUiSettings.setTiltGesturesEnabled(false)// 设置地图是否可以倾斜

mUiSettings.setScaleControlsEnabled(true)// 设置地图默认的比例尺是否显示

mUiSettings.setZoomControlsEnabled(false)

initMapListener()

}

private void initMapListener() {

aMap.setOnMapLoadedListener(this)

aMap.setOnCameraChangeListener(this)

aMap.setOnMarkerClickListener(this)

aMap.setOnInfoWindowClickListener(this)

aMap.setInfoWindowAdapter(this)// 设置自定义InfoWindow样式

aMap.setOnMapClickListener(this)

centerMarker.setAnimationListener(this)

locate.setOnClickListener(this)

}

/**

* 方法必须重写

*/

@Override

protected void onResume() {

super.onResume()

mapView.onResume()

}

/**

* 方法必须重写

*/

@Override

protected void onPause() {

super.onPause()

mapView.onPause()

}

/**

* 方法必须重写

*/

@Override

protected void onSaveInstanceState(Bundle outState) {

super.onSaveInstanceState(outState)

mapView.onSaveInstanceState(outState)

}

/**

* 方法必须重写

*/

@Override

protected void onDestroy() {

super.onDestroy()

mapView.onDestroy()

}

@Override

public void onLocationChanged(Location location) {

}

@Override

public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override

public void onProviderEnabled(String provider) {

}

@Override

public void onProviderDisabled(String provider) {

}

@Override

public void onLocationChanged(AMapLocation aLocation) {

if (aLocation != null) {

this.aLocation = aLocation

if (mListener != null)

mListener.onLocationChanged(aLocation)// 显示系统小蓝点

if (isFirst) {

isFirst = false

aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(

aLocation.getLatitude(), aLocation.getLongitude())))

CameraUpdateFactory.zoomTo(16)

MarkerOptions markerOption = new MarkerOptions()

markerOption.position(new LatLng(aLocation.getLatitude(),

aLocation.getLongitude()))

markerOption.title("上海市").snippet("上海:34.341568, 108.940174")

markerOption.draggable(true)

Marker marker = aMap.addMarker(markerOption)

marker.setObject("11")//这里可以存储用户数据

}

}

}

@SuppressWarnings("deprecation")

@Override

public void activate(OnLocationChangedListener listener) {

mListener = listener

if (aMapManager == null) {

aMapManager = LocationManagerProxy.getInstance(this)

/*

* 1.0.2版本新增方法,设置true表示混合定位中包含gps定位,false表示纯网络定位,默认是true

*/

// Location API定位采用GPS和网络混合定位方式,时间最短是2000毫秒

aMapManager.requestLocationUpdates(

LocationProviderProxy.AMapNetwork, 2000, 10, this)

}

}

/**

* 停止定位

*/

@Override

public void deactivate() {

mListener = null

if (aMapManager != null) {

aMapManager.removeUpdates(this)

aMapManager.destory()

}

aMapManager = null

}

@Override

public boolean onMarkerClick(Marker marker) {

currentMarker = marker

Log.e("marker", marker.getObject() + "marker: " + marker.getPosition().latitude+" : "+marker)

return false

}

@Override

public View getInfoContents(Marker marker) {

Log.e("marker",

marker.getObject() + "getInfoContents: " + marker.getId())

return null

}

@Override

public View getInfoWindow(Marker marker) {

Log.e("marker", marker.getObject() + "getInfoWindow: " + marker.getId())

View infoWindow = getLayoutInflater().inflate(

R.layout.custom_info_window, null)

render(marker, infoWindow)

return infoWindow

}

@Override

public void onInfoWindowClick(Marker marker) {

Log.e("marker",

marker.getObject() + "onInfoWindowClick: " + marker.getId())

}

@Override

public void onMapLoaded() {

centerImageView.startAnimation(centerMarker)

CameraUpdateFactory.zoomTo(16)

Log.e("load", "onMapLoaded")

}

@Override

public void onCameraChange(CameraPosition arg0) {

}

@Override

public void onCameraChangeFinish(CameraPosition arg0) {

centerImageView.startAnimation(centerMarker)

Log.e("load", "onCameraChangeFinish+获取后台数据")

}

@Override

public void onAnimationStart(Animation animation) {

centerImageView.setImageResource(R.drawable.green_pin_lift)

}

@Override

public void onAnimationRepeat(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

centerImageView.setImageResource(R.drawable.green_pin)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11534833.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存