美文网首页
做地图界面小结

做地图界面小结

作者: 天城一哥 | 来源:发表于2016-09-05 21:08 被阅读146次

1.在Pods中导入AMap2DMap,AMapFoundation,AMaplocation,AMapSearch,PKHUD工具
2.创建一个OC桥接文件,导入:

import <AMapSearchKit/AMapSearchKit.h>

import <MAMapKit/MAMapKit.h>

import <AMapFoundationKit/AMapFoundationKit.h>

import <MAMapKit/MAMapView.h>

import <AMapLocationKit/AMapLocationKit.h>

import <Foundation/Foundation.h>

import <AMapSearchKit/AMapSearchAPI.h>

3.在OneMapViewController界面中继承
MAMapViewDelegate,AMapSearchDelegate,AMapLocationManagerDelegate,UIGestureRecognizerDelegate并关联

定义全局变量:
var mapView:MAMapView?
var search:AMapSearchAPI!
var searchButton:UIButton!
//两个位置,一个固定,一个动,计算距离
var coordinatePoint:MAMapPoint! //坐标(随便自己点的位置)
var locationPoint:MAMapPoint! //位置(固定位置)

5.添加一系列函数:
1)初始化地图:

func initMapView(){
    let compassX = mapView?.compassOrigin.x
    let scaleX = mapView?.scaleOrigin.x
    
    //设置指南针和比例尺的位置
    mapView?.compassOrigin = CGPointMake(compassX!,21)
    mapView?.scaleOrigin = CGPointMake(scaleX!,21)
    mapView = MAMapView(frame:self.view.bounds)
    mapView?.delegate = self

// self.view.addSubview(mapView!)
// self.view.sendSubviewToBack(mapView!)
// mapView!.mapType = .Satellite
mapView!.showsUserLocation = true//开启定位
self.view.addSubview(mapView!)
self.view.sendSubviewToBack(mapView!)
//设置用户是否自定义范围circle
// mapView?.customizeUserLocationAccuracyCircleRepresentation = true
// mapView!.userTrackingMode = MAUserTrackingModeFollow
// mapView?.allowsBackgroundLocationUpdates = true
mapView?.userTrackingMode = .Follow
mapView!.distanceFilter = 500.0
mapView!.desiredAccuracy=kCLLocationAccuracyBestForNavigation
}
2).
添加大头针:
func mapView(mapView: MAMapView, viewForAnnotation annotation: MAAnnotation) -> MAAnnotationView? {

    if annotation.isKindOfClass(MAPointAnnotation) {
        let annotationIdentifier = "invertGeoIdentifier"
        var poiAnnotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) as? MAPinAnnotationView
        
        if poiAnnotationView == nil {
            poiAnnotationView = MAPinAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
        }
        //设置动画显示,默认为NO
        poiAnnotationView!.animatesDrop   = true
        //设置气泡可以弹出,默认为NO
        poiAnnotationView!.canShowCallout = true
        //设置大头针颜色
        poiAnnotationView?.pinColor = MAPinAnnotationColor.Purple
        poiAnnotationView?.image = UIImage(named: "sport-car.png")
        //            poiAnnotationView!.canShowCallout = true    //设置气泡可以弹出,默认为NO
        //            poiAnnotationView!.animatesDrop = true    //设置标注动画显示,默认为NO
        //           poiAnnotationView!.draggable = true   //设置标注可以拖动,默认为NO
        //            poiAnnotationView!.pinColor = MAPinAnnotationColor.Green
        return poiAnnotationView
    }
    return nil
}

3).
//逆地理编码回调
func onReGeocodeSearchDone(request: AMapReGeocodeSearchRequest, response: AMapReGeocodeSearchResponse) {
if (response.regeocode != nil) {
let coordinate = CLLocationCoordinate2DMake(Double(request.location.latitude), Double(request.location.longitude))
let annotation = MAPointAnnotation()
annotation.coordinate = coordinate
annotation.title = response.regeocode.formattedAddress
annotation.subtitle = response.regeocode.addressComponent.province
print(annotation.title) //获取位置具体信息
mapView!.addAnnotation(annotation)
let overlay = MACircle(centerCoordinate: coordinate, radius: 40.0) //添加大头针的半径
mapView!.addOverlay(overlay)
}
}
//逆地理编码请求
func oppositeGeoCodeRequeset(coor: CLLocationCoordinate2D){
let searchRequest = AMapReGeocodeSearchRequest()
searchRequest.location = AMapGeoPoint.locationWithLatitude(CGFloat(coor.latitude), longitude: CGFloat(coor.longitude))
self.search.AMapReGoecodeSearch(searchRequest)
}

4.其余添加
reloadMap,initSearch,initGestureRecognizer,searchReGeocodeWithCoordinate, gestureRecognizer,handleLongPress,mapView(mapView: MAMapView , didUpdateUserLocation userLocation: MAUserLocation ) ,twoPointDistance,dangerousWarn,
mapView(mapView: MAMapView, rendererForOverlay overlay: MAOverlay) -> MAOverlayRenderer?函数,intAddWarn

相关文章

  • 做地图界面小结

    1.在Pods中导入AMap2DMap,AMapFoundation,AMaplocation,AMapSearc...

  • Layer弹层(父子传值,兄弟传值)

    需求:最外面列表界面点修改弹出LayerA界面,再点击LayerA界面中的选择地图坐标按钮弹出LayerB地图界面...

  • Day.02.12 javascript 接触篇

    小结:I.js一般放在head标签之间 //alert js可以做什么?1.可以做游戏,网页的特性,地图,web聊...

  • 人像后期-液化

    -本文大纲- ①打开液化界面 ②常用液化工具介绍及运用 ③小结 -打开液化界面- 进入液化界面的两种方式: ①快捷...

  • 产业经济监测、预测与政策模拟平台功能 (Mobile版)

    一、实时监测 界面上面是页面切换按钮、用户登录信息、地图显示部分,交易额前五,地图图例信息。 界面下面是各地区交易...

  • Day.02.03 div之清除浮动

    小结:清除浮动后不受浮动约束,用来和浮动组合,搭建界面!

  • (3)各种事件监听

    百度地图有几个重要的事件监听 比如说地图加载完成,地图渲染完成,地图状态改变监听 从其他界面返回,会回调地图渲染完...

  • 百度地图相关

    地图不能拖动问题 如果不能销毁的界面,离开界面执行[mapView viewWillDisappear]后,不要在...

  • 服务地图小结

    一、服务地图介绍 服务地图也称作体验地图,可贯穿体验始终,涵盖了用户角色,心情体验图等用户研究部分,也包括体验流程...

  • quasar上高德地图vue-amap组件应用攻略:基础篇

    在quasar应用中以电子地图作为主界面是一种很好的交互界面探索,笔者选用高德地图的vue-amap组件,具体原因...

网友评论

      本文标题:做地图界面小结

      本文链接:https://www.haomeiwen.com/subject/vaorettx.html