当前位置: 首页 > 编程日记 > 正文

swift 中高德地图随时读取坐标地点的写法

自己写的方法  不比比  自己能看懂就行   只用作自己学习swift的总结



import UIKit


typealias block = (String,String) ->()


class MoveCarViewController: UIViewController,MAMapViewDelegate,AMapLocationManagerDelegate,AMapSearchDelegate,UITextFieldDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate {

    

    //大视图

    @IBOutlet weak var bgView: UIView!

    

    //小车按钮

    @IBOutlet weak var smallCarButton: UIButton!

    

    //大车按钮

    @IBOutlet weak var bigCarButton: UIButton!

    

    

    //车牌选择按钮

    @IBOutlet weak var plateButton: UIButton!

    

    //车牌号输入框

    

    @IBOutlet weak var plateTextFild: UITextField!

    

    //选择照片按钮

    @IBOutlet weak var photoButton: UIButton!

    

    //存放照片view

    @IBOutlet weak var ImageView: UIView!

    

    //存放照片button

    @IBOutlet weak var ImageButton: UIButton!

       

    //存放地图视图的地板

    

    @IBOutlet weak var firstView: UIView!

    

    

    //手动上报位置按钮

    @IBOutlet weak var manualButton: UIButton!

    

    //位置信息label


    @IBOutlet weak var locationLabel: UILabel!

    

    

    //提交按钮

    @IBOutlet weak var submitButton: UIButton!

    

    var popView : PopoverView?

    

    var db : FMDatabase?

    

    //车牌数据

    lazy var plates : [String] = {

        

        return PlateNumber.PlateNumbers() as! [String]

        

    }()

    

    var imageOne : UIButton?

    

    var imageTwo : UIButton?

    

    var index = 1

    

    var imageFileStr : String? = ""

    

    //对方车牌号

    var HPHM = UITextField()

    

    //挪车地址

    var Address = UILabel()

    

    //当前选中机动车类型

    

    var vehicleType1 = CarType()

    

    var vehicleType2 = CarType()

    

    var tmpcoordinate = CLLocationCoordinate2D()

    

    var carTypes : NSMutableArray!

    

    var carCitys : NSMutableArray!

    

    var tmpcity : String = ""

    

    var uploadFileList : NSMutableArray!

    

    var currentSelectedButton : UIButton = UIButton()

  

    var backImage : UIImageView!

    

    var label = UILabel()

    

    var city : String!

    

    var mapView : MAMapView?

    

    var search : AMapSearchAPI?

    

    var centerMarker : UIButton!

    

    var mapLacationManager = AMapLocationManager()

    

    var centerCoordinate:CLLocationCoordinate2D?

    

    //追踪指针位置的移动

    func mapView(mapView: MAMapView!, regionDidChangeAnimated animated: Bool) {

        

        delAddress()

        

    }

    

    var myBlock : block!

    



    

    

    

    

    //执行查询语句

    func searchCarType() {

        

                var resultSet : FMResultSet? = db?.executeQuery("SELECT rowid, * FROM chePaiType  ORDER BY rowid ASC;", withArgumentsInArray: nil)

        

                var tmparray : NSMutableArray = NSMutableArray.init(capacity: 2)

        

                //遍历结果

        

                while ((resultSet?.next()) != nil) {

        

                    var modle : CarType = CarType()

        

                    modle.rowid = Int(resultSet!.intForColumn("rowid"))

                    

                    modle.dm_code = String(resultSet!.intForColumn("dm_code"))

                    

                    modle.dm_name = String(resultSet!.intForColumn("dm_name"))

                    

                    modle.yx_biaoshi = String( resultSet!.intForColumn("yx_biaoshi"))

                    

                    

                    

        

                }

        

           self.carTypes = tmparray

    }

    

    //查询

    func searchCarCity() {

        

        //1.执行查询语句

        var resultSet : FMResultSet = (db?.executeQuery("SELECT rowid, * FROM chePaiCity;", withArgumentsInArray: nil))!

        

        //2.遍历结果

        

        var tmparray : NSMutableArray = NSMutableArray.init(capacity: 2)

        

        while resultSet.next() {

            

            var model : CarCity = CarCity()

            

            

            

            model.rowid = Int(resultSet.intForColumn("rowid"))

            

            model.city_name = String(resultSet.intForColumn("city_name"))

            

            model.cp_daihao = String(resultSet.intForColumn("cp_daihao"))

            

            

        }

        

        self.carCitys = tmparray

        

    }

    

    

    

    

    //查询当前默认城市的发证机关

    

    func searchCurCity(city: String) {

        

        var SQLStr : String = String.init(format: "SELECT rowid, * FROM chePaiCity WHERE city_name =\"%@\"", city)

        

        var resultSet : FMResultSet = (db?.executeQuery(SQLStr, withArgumentsInArray: nil))!

        

        while resultSet.next() {

            

            plateTextFild.text = resultSet.stringForColumn("cp_daihao") .stringByReplacingOccurrencesOfString(" ", withString: "")

            

        }

    }

    

    


    

    

    

    override func viewDidDisappear(animated: Bool) {

        

        super.viewDidDisappear(animated)

        

        self.mapView?.showsUserLocation = false

        

        self.mapView?.delegate = nil

        

        self.search!.delegate = nil

        

        

        

        

    }


    override func viewDidAppear(animated: Bool) {

        

        super.viewDidAppear(animated)

        

        self.mapView?.delegate = self

        

        self.search?.delegate = self

        

    }

    

    

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        self.view.backgroundColor = UIColor.whiteColor()

        

        

        

        title = "挪车服务"

        

        

        MAMapServices.sharedServices().apiKey = APIKey

        

        AMapSearchServices.sharedServices().apiKey = APIKey

        

        search = AMapSearchAPI()

        

        search?.delegate = self

        

        var uploadFileList : NSMutableArray = NSMutableArray.init(capacity: 2)

        

        

        initMapView()

        

        initBtns()



        

//        if ([self .respondsToSelector(automaticallyAdjustsScrollViewInsets)]) {

//            

//            self.automaticallyAdjustsScrollViewInsets = false

//        

//        }

//        

//        if ([self .respondsToSelector(setEdgesForExtendedLayout:)]) {

//            

//            self.edgesForExtendedLayout = UIRectEdge.None

//            

//            

//        }

        

        


        //历史

        var HistoryItem : UIBarButtonItem = UIBarButtonItem.init(title: "历史", style: UIBarButtonItemStyle.Done, target: self, action: "historyTapped")

        

        self.navigationItem.rightBarButtonItem = HistoryItem

        

        var path : String = NSConfig.filePath()

        

        var db : FMDatabase = FMDatabase(path : path)

        

        if db .open() {

            

            self.db = db

            

            

            db.close()

            

        } else {

            

            print("数据库打开成功")

            

        }

        

        self.tmpcity = ""

        

        

        

        makeUpButton()

        

        initView()

        

        getUserLocation()

        

    }


    

    //点击空白  收回键盘

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        

        view.endEditing(true)

    }

    

    //MARK: - 初始化控件

    

    private func setpUI() {

        

        

        

        

    }

    

    func initMapView() {

        

        mapView = MAMapView(frame: self.firstView.bounds)

        

        //是否显示用户位置

        mapView?.showsUserLocation = true

        

        //设定定位的最小更新距离

        mapView!.distanceFilter=16.0

        

        //追踪用户的location更新

        mapView?.setUserTrackingMode(MAUserTrackingMode.Follow, animated: true)

        

        //是否显示罗盘,默认为YES

        mapView?.showsCompass = true

        

        //是否显示比例尺,默认为YES

        mapView?.showsScale = true

        

        //地图比例尺级别

        mapView?.zoomLevel = 16

        

        //比例尺位置

        mapView?.scaleOrigin = CGPointMake(SCREEN_WIDTH * 0.00997, 0.0075)

        

        mapLacationManager = AMapLocationManager()

        

        mapView?.delegate = self

        

        mapLacationManager.requestLocationWithReGeocode(true) {

            

            (location, reGeocode, error) -> Void in

            

        }

        

        //设定定位精度

        mapView!.desiredAccuracy=kCLLocationAccuracyBestForNavigation

        

        mapView?.desiredAccuracy = kCLLocationAccuracyBest

        

        firstView!.addSubview(mapView!)

        

        

        

        

    }

    

    func initBtns() {

        

        //指针

        centerMarker = UIButton(frame: CGRectMake(0, 0, SCREEN_WIDTH * 0.0535, SCREEN_WIDTH * 0.5))

        

        centerMarker.center = (mapView?.center)!

        

        centerMarker.frame = CGRectMake(SCREEN_WIDTH * 0.45, SCREEN_HEIGHT * 0.2, SCREEN_WIDTH * 0.1090, SCREEN_WIDTH * 0.09)

        

        centerMarker.setImage(UIImage(named: "指针"), forState: .Normal)

        

        centerMarker.addTarget(self, action: "tappedOnee", forControlEvents: .TouchUpInside)

        

        mapView?.addSubview(centerMarker)

        

        

        //label

        

        label = UILabel(frame: CGRectMake(SCREEN_WIDTH * 0.5, SCREEN_HEIGHT * 0.190 , SCREEN_WIDTH * 0.8, SCREEN_WIDTH * 0.02725))

        

        label.center = (mapView?.center)!

        

        label.text = "地址"

        

        label.textAlignment = NSTextAlignment.Center

        

        label.numberOfLines = 0

        

        label.layer.cornerRadius = 3.0

        

        label.layer.masksToBounds = true

        

        label.font = UIFont.systemFontOfSize(14.0)

        

        label.backgroundColor = UIColor.init(white: 0, alpha: 0.6)

        

        label.textColor = UIColor.whiteColor()

        

        

        //  self.view.addSubview(label)

        

        //文字大小自适应标签宽度

        label.adjustsFontSizeToFitWidth=true

        

        label.numberOfLines=2

        

        label.frame = CGRectMake(SCREEN_WIDTH * 0.1, SCREEN_HEIGHT * 0.15 , SCREEN_WIDTH * 0.8, SCREEN_WIDTH * 0.109)

        

        

        // label.hidden = true

        

        mapView?.addSubview(label)

        

        

        

        

        

        //定位按钮

        var locationBtn: UIButton = UIButton(frame: CGRectMake(SCREEN_WIDTH * 0.0409, SCREEN_HEIGHT * 0.4, SCREEN_WIDTH * 0.1054, SCREEN_WIDTH * 0.1054))

        

        locationBtn.setImage(UIImage(named: "定位"), forState: .Normal)

        

        locationBtn.tag = 101

        

        locationBtn.addTarget(self, action: "btnSelector:", forControlEvents: .TouchUpInside)

        

        mapView?.addSubview(locationBtn)

        

        //刷新按钮

        var refreshBtn:UIButton = UIButton(frame: CGRectMake(SCREEN_WIDTH * 0.0409, SCREEN_HEIGHT * 0.35, SCREEN_WIDTH * 0.1054, SCREEN_WIDTH * 0.1054))

        

        refreshBtn.setImage(UIImage(named: "刷新"), forState: .Normal)

        

        refreshBtn.tag = 102

        

        refreshBtn.addTarget(self, action: "btnSelector:", forControlEvents: .TouchUpInside)

        

        mapView?.addSubview(refreshBtn)

        

        //缩小按钮

        var zoomOutBtn: UIButton = UIButton(frame: CGRectMake(SCREEN_WIDTH * 0.87, SCREEN_HEIGHT * 0.41, SCREEN_WIDTH * 0.085, SCREEN_WIDTH * 0.085))

        

        zoomOutBtn.setImage(UIImage(named: "缩小"), forState: .Normal)

        

        zoomOutBtn.tag = 103

        

        zoomOutBtn.addTarget(self, action: "btnSelector:", forControlEvents: .TouchUpInside)

        

        mapView?.addSubview(zoomOutBtn)

        

        //放大按钮

        var zoomInBtn : UIButton = UIButton(frame: CGRectMake(SCREEN_WIDTH * 0.87, SCREEN_HEIGHT * 0.37, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08))

        

        zoomInBtn.tag = 104

        

        zoomInBtn.setImage(UIImage(named: "放大"), forState: .Normal)

        

        

        zoomInBtn.addTarget(self, action: "btnSelector:", forControlEvents: .TouchUpInside)

        

        mapView?.addSubview(zoomInBtn)

        

        

        

        

    }

    

    //按钮的实现方法

    func btnSelector(sender: UIButton) {

        

        switch sender.tag {

        case 101: //定位

            

            if centerCoordinate != nil {

                

                mapView?.setCenterCoordinate(centerCoordinate!, animated: true)

                

                

                

            }

            

        case 102: //刷新

            

           getLocationRoundFlag()

            

            mapView?.showsUserLocation = true //YES 为打开定位,NO 为关闭定位

            

        case 103: //缩小

            

            

            if mapView?.zoomLevel >= 4 && mapView?.zoomLevel <= 19 {

                

                mapView?.setZoomLevel((mapView?.zoomLevel)! - 1, animated: true)

                

            }else if mapView?.zoomLevel >= 3 && mapView?.zoomLevel < 4 {

                

                mapView?.setZoomLevel(3, animated: true)

            }

            

            

            

        case 104: //放大

            

            

            if mapView?.zoomLevel >= 3 && mapView?.zoomLevel <= 18 {

                

                mapView?.setZoomLevel((mapView?.zoomLevel)! + 1, animated: true)

                

            } else if mapView?.zoomLevel > 18 && mapView?.zoomLevel <= 19 {

                

                mapView?.setZoomLevel(19, animated: true)

                

            }

            

            

        default:

            

            print("not know")

            

        }

        

    }

    

    func tappedOnee() {

        

    }

    

    

    func getLocationRoundFlag(){

        

    }

    

    

    func mapView(mapView: MAMapView!, didUpdateUserLocation userLocation: MAUserLocation!, updatingLocation: Bool) {

        

        if updatingLocation {

            

            centerCoordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude);

            

            

        }

    }

    

    

    //跟随态

    func startFollowing() {

        

        mapView?.showsUserLocation = true

        

        mapView?.userTrackingMode = MAUserTrackingMode.FollowWithHeading

        

    }

    

    

    func confirm() {

      

        

        self.myBlock = {(address:String,city : String) ->() in

            

            let c = address.stringByAppendingFormat(self.label.text!, self.city)

            print(c)

            

            var VC : MoveCarViewController?

            

            VC?.locationLabel.text = self.label.text

            

        }

        

       

        

        self.navigationController?.popViewControllerAnimated(true)

        

    }

    

    

    func delAddress() {

        

        var point = CGPoint()

        

        point = CGPointMake(10, 10)

        

        var center = (mapView?.convertPoint(point, toCoordinateFromView: self.mapView))!

        

        self.searchReGeocodeWithCoordinate(center)

        

        locationLabel.text = label.text

        

       


        

    }

    

    

    

    

    

    //逆地理编码

    

    func searchReGeocodeWithCoordinate(coordinate:CLLocationCoordinate2D!) {

        

        let rego : AMapReGeocodeSearchRequest = AMapReGeocodeSearchRequest()

        

        rego.location = AMapGeoPoint.locationWithLatitude(CGFloat(coordinate.latitude), longitude: CGFloat(coordinate.longitude))

        

        rego.requireExtension = true

        

        self.search!.AMapReGoecodeSearch(rego)

        

        

    }

    

    //MARK:- MAMapViewDelegate

    

    func mapView(mapView: MAMapView!, didLongPressedAtCoordinate coordinate: CLLocationCoordinate2D) {

        

        searchReGeocodeWithCoordinate(coordinate)

        

    }

    

    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)

                

            }

            

            poiAnnotationView!.pinColor = MAPinAnnotationColor.Green

            

            poiAnnotationView!.animatesDrop = true

            

            poiAnnotationView?.draggable = true

            

            poiAnnotationView!.canShowCallout = true

            

            return poiAnnotationView

            

        }

        

        return nil

        

    }

    

    

    //MARK:- AMapSearchDelegate

    

    

    func AMapSearchRequest(request: AnyObject!, didFailWithError error: NSError!) {

        

       

    }

    

    func onReGeocodeSearchDone(request: AMapReGeocodeSearchRequest, response: AMapReGeocodeSearchResponse) {

        

        if (response.regeocode != nil) {

            

            label.text = response.regeocode.formattedAddress

            

            let tddd : AMapAddressComponent = response.regeocode.addressComponent

            

            self.city = tddd.city

            

            self.mapView?.showsUserLocation = true

            

            

        }

    }

    

    

    //清楚数据

    func clearMapData() {

        

        clearMapView()

        

        clearSearch()

        

    }

    

    func clearMapView(){

        

        mapView!.showsUserLocation = false

        

        mapView!.delegate = nil

    }

    

    func clearSearch(){

        

        self.search!.delegate = nil

        

    }

    

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }


    

    

    

    

    //按钮实现方法

    

    func makeUpButton() {

        

        //小车按钮

        smallCarButton.addTarget(self, action: "tappedOne", forControlEvents: .TouchUpInside)

        

        smallCarButton.tag = 101

        

        //边框

        smallCarButton.layer.borderWidth = 1

        

        smallCarButton.layer.borderColor = UIColor.lightGrayColor().CGColor

        

        smallCarButton.layer.cornerRadius = 5

        

        smallCarButton.clipsToBounds = true

        

//        //字体颜色变化

//        

//        smallCarButton.setTitleColor(UIColor.greenColor(), forState: .Selected)

//        

//

//        

//           smallCarButton.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)

//        

//        

        

        

        //大车按钮

        bigCarButton.addTarget(self, action: "tappedTwo", forControlEvents: .TouchUpInside)

        

        bigCarButton.tag = 102

        

       //边框

        bigCarButton.layer.borderWidth = 1

        

        bigCarButton.layer.borderColor = UIColor.lightGrayColor().CGColor

        

        bigCarButton.layer.cornerRadius = 5

        

        bigCarButton.clipsToBounds = true

        

       // bigCarButton.setTitle("大车", forState: .Normal)

//        bigCarButton.setTitleColor(UIColor.greenColor(), forState: .Selected)

        

        

        //车牌选择按钮

        plateButton.addTarget(self, action: "tappedThree:", forControlEvents: .TouchUpInside)

        

        plateButton.setImage(UIImage(named: "home_img_down"), forState: .Normal)

        

        plateButton.tag = 103

        

        

        //选择照片按钮

        photoButton.addTarget(self, action: "tappedFour", forControlEvents: .TouchUpInside)

        

        photoButton.tag = 104

        

        //上报位置按钮

        //locationButton.addTarget(self, action: "tappedFive", forControlEvents: .TouchUpInside)

        

        //locationButton.tag = 105

        

        //locationButton.setImage(UIImage(named: "moveCar_position_one"), forState: .Normal)

        

        //手动上传位置

       // manualButton.addTarget(self, action: "tappedSix:", forControlEvents: .TouchUpInside)

        

       // manualButton.tag = 106

        

       // manualButton.setImage(UIImage(named: "moveCar_position_two"), forState: .Normal)

        

        //位置信息label

        locationLabel.layer.cornerRadius = 5

        

        locationLabel.clipsToBounds = true

        

        

        

        //提交按钮

        submitButton.addTarget(self, action: "tappedSeven", forControlEvents: .TouchUpInside)

        

        submitButton.tag = 107

        

        submitButton.layer.cornerRadius = 5

        

        submitButton.clipsToBounds = true

        

        //大底板的边框

        bgView.layer.borderWidth = 1

        

        bgView.layer.borderColor = UIColor.lightGrayColor().CGColor

        

        bgView.layer.cornerRadius = 5

        

        bgView.clipsToBounds = true

        

        //照片view

        ImageView.layer.cornerRadius = 5

        

        ImageView.clipsToBounds = true

        

        

        //存放照片按钮

        ImageButton.addTarget(self, action: "tappedEight", forControlEvents: .TouchUpInside)

        

        ImageButton.tag = 108

        

        

        //车牌照输入框实现

        plateTextFild.keyboardType = UIKeyboardType.ASCIICapable

        

        plateTextFild.layer.borderColor = UIColor.init(white: 0.800, alpha: 1.00).CGColor

        

        plateTextFild.addTarget(self, action: "tappedNine:", forControlEvents: UIControlEvents.EditingChanged)

        

        plateButton.tag = 109

        

    

    }

    

    

    

    

    

    func historyTapped() {

        

        var VC = HistoryViewController()

        

        self.navigationController?.pushViewController(VC, animated: true)

        

    }

    

    func tappedOne() {

        

        print("我是第一个")

        

        currentSelectedButton.selected = false

        

        currentSelectedButton = smallCarButton

        

        currentSelectedButton.selected = true

        

        currentSelectedButton.setTitleColor(RGBA(62, g: 151, b: 210, a: 1.0), forState: UIControlState.Selected)

        

    }

    

        

    

    func tappedTwo() {

        

        print("我是第二个")

        

        currentSelectedButton.selected = false

        

        currentSelectedButton = bigCarButton

        

        currentSelectedButton.selected = true

        

        currentSelectedButton.setTitleColor(RGBA(62, g: 151, b: 210, a: 1.0), forState: UIControlState.Selected)

        

        

    }

    


    func tappedThree(btn : PlateBtn) {

        

        print("我是第三个")

        

        if popView != nil && popView!.isShow {

            

            popView?.dismiss(true)

            

        } else {

            

            popView = PopoverView(point: CGPointMake(btn.x + 30, CGRectGetMaxX(btn.frame) + 80), titles: plates, images: nil)

            

            popView?.show()

            

            popView?.selectRowAtIndex = {(row : Int) in

                btn.setTitle(self.plates[row], forState: UIControlState.Normal)

                

            }


            

        }

        

    }

    


    

    

    

    func tappedFour() {

        

        print("我是第四个")

        

        

        let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "相机", "相册")

        

        actionSheet.showInView(view)

        

        

        

    }

    

    func tappedFive() {

        

        print("我是第五个")

        

    }

    

    func tappedSix(gestureRecognizer : UITapGestureRecognizer) {

        

        //view.endEditing(true)

        

        print("我是第六个")

        

        let VC = MoveCarMapViewController()

        

        VC.centerCoordinate = tmpcoordinate


        VC.myBlock = {(address:String,city : String) ->() in

            

            self.locationLabel.text = address.stringByAppendingFormat(VC.label.text!, VC.city)

            

            self.tmpcity = city

            

                  

        }

        

        

        

        print(self.locationLabel.text)

        

        print(VC.label.text)

        

        print(VC.myBlock)

        

        navigationController?.pushViewController(VC, animated: true)

        


        

    }

    

    

    

    

    func tappedSeven() {

        

        print("我是第七个")

        

        var model : CarCity = CarCity()

        

//        var modelOne : ShareModel = ShareModel()

//        

//        if (!modelOne.NetWorking) {

//            

//            NSHelper.showAlertTitle("网络不可用,请检查网络连接。", forView: self.view)

//            

//            return

//            

//        }

    

        if (NSString.isNullOrEmpty(locationLabel.text)) {

            

            NSHelper.showAlertTitle("", message: "暂无法定位,请检查网络。", cancel: "确定")

            

            return

            

        }

        

        if (NSString.isNullOrEmpty(plateTextFild.text)) {

            

            NSHelper.showAlertTitle("请查看对方车牌号码是否输入正确?", forView: self.view)

            

            return

            

        }

        

        if (self.uploadFileList.count < 1) {

            

            NSHelper.showAlertTitle("", message: "请至少上传一张图片", cancel: "确定")

            

            return

        }

        

        let alert : UIAlertView = UIAlertView.init(title: nil, message: "确认提交挪车", delegate: nil, cancelButtonTitle: "确定")

        

        alert.showAlertViewWithCompleteBlock { (buttonIndex : NSInteger) in

            

            if (buttonIndex == 1) {

                

                //提交车辆信息

                

                let model : LocationModel = LocationModel()

                

                var species : String = ""

                

                if self.currentSelectedButton.titleLabel?.text == "小车" {

                    

                    species = "02"

                    

                }else {

                    

                    species = "01"

                    

                }

                

                

                let s = (self.plateTextFild.text! as NSString).substringToIndex(2)

                

                let dic : [String : AnyObject] = Dictionary(dictionaryLiteral: ("address" , self.locationLabel.text!),("mobile" , model.mobile),("vehicleType" , species),("vehicleType1",species),("city" , self.tmpcity),("fzjg" ,self.plateTextFild.text!),("userId" , model.userID),("vehicleNum" , s.stringByAppendingString(self.HPHM.text!)))

                

                let httpStr : String = AFAppDotNetAPIBaseURLString.stringByAppendingString(cfg.moveVehicle())

                

                print(httpStr)

                

                let HttpURL = httpStr.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)

                

                let imageName : String = (self.uploadFileList.firstObject)! as! String

                

                let imageData : NSData = NSData.init(contentsOfFile: NSHelper.readDocumentsWithFileName(imageName))!

               

                

                let tools = NetWorkTools.sharedNetWorkTools()

                

                let parmeters  = ["suth" :tools.toAuthJSONString(),"info" : tools.toJSONString(dic),"picName" : imageName]

                

                print(parmeters)

                

                

                let hud : MBProgressHUD = MBProgressHUD.init(view: self.view)

                

                self.view.addSubview(hud)

                

                hud.labelText = "挪车提醒发送中..."

                

                hud.show(true)

                

                //发起网络请求

                let manager : AFHTTPRequestOperationManager = AFHTTPRequestOperationManager()

                

               // manager.responseSerializer = [AFHTTPRequestSerializer serializer]

                

               // manager.responseSerializer = [AFJSONResponseSerializer serlailzer]

                

                manager.responseSerializer.acceptableContentTypes = NSSet.init(object: "text/html") as Set<NSObject>

                

                let operation : AFHTTPRequestOperation? = manager.POST(HttpURL!, parameters: parmeters, constructingBodyWithBlock: { (formData :AFMultipartFormData) in

                    

                    formData.appendPartWithFileData(imageData, name: "picFile", fileName: imageName, mimeType: "image/png")

                    

                    }, success: { (operation : AFHTTPRequestOperation, responseObject : AnyObject) in

                        

                        hud.hide(true)

                        

                        if dic["errCode"]?.integerValue == 0 {

                            

                            NSHelper.showAlertTitle(nil, message: "短信已发送至车主,请耐心等待!", cancel: "确定")

                            

                            self.HPHM.text = ""

                            

                            let cache : String = NSHelper.getUploadFileBasePath()

                            

                           try! NSFileManager.defaultManager().removeItemAtPath(cache)

                            

                           self.uploadFileList.removeAllObjects()

                            


                            

                        }else {

                            

                            NSHelper.showAlertTitle(nil, message: dic["msg"] as? String, cancel: "确定")

                            

                        }

                        

                    }, failure: { (operation : AFHTTPRequestOperation, error : NSError) in

                        

                        hud.hide(true)

                        

                        NSHelper.showAlertTitle(nil, message: "服务器异常,请稍后再试。", cancel: "确定")

                        

                        

                })

                

                

                

            }

           

        }

        

        

    }

    

    

    func tappedEight() {

        

        print("我是第八个,用来存照片的")

        

        

    }

    

    

    func tappedNine(textField: UITextField) {

        

        textField.text = textField.text?.uppercaseString

        

        plateTextFild.delegate = self

        

        textField.delegate = self

        

        

        

        if (textField == plateTextFild) {

            

            if (textField.text?.characters.count > 5) {

                

                textField.text = textField.text?.substringToIndex((textField.text?.startIndex.advancedBy(5))!)

                

                

            }

            

        }

        

    }

    

    

//    func dataToJsonString(object : AnyObject) {

//        

//        var jsonString : String = ""

//        

//        var error : NSError?

//        

//        let jsonData =  NSJSONSerialization.dataWithJSONObject(object, options: NSJSONWritingOptions.PrettyPrinted,error:nil)

//        

//        if (jsonData == "") {

//            

//            print(error)

//            

//        } else {

//            

//            jsonString = String.init(data: jsonData, encoding: NSUTF8StringEncoding)!

//            

//        }

//        

//        return

//    }

//    

    

    

    func initView() {

        

//        let tmpp : CarType = ((self.carTypes?.firstObject)! as? CarType)!

//        

//        

//        plateTextFild.text = tmpp.dm_name

//        

//        vehicleType1 = tmpp

//        

//        plateTextFild.rightViewMode = UITextFieldViewMode.Always

//        

//        plateTextFild.rightView = plateButton

        

        

        //对方车牌号

        HPHM.borderStyle = UITextBorderStyle.RoundedRect

        

        HPHM.autocapitalizationType = UITextAutocapitalizationType.AllCharacters

        

        HPHM.keyboardType = UIKeyboardType.ASCIICapable

        

        HPHM.addTarget(self, action: "textFiledEditChanged:", forControlEvents: UIControlEvents.EditingChanged)

        

    }

    

    

    func getUserLocation() {

        

        self.mapView?.showsUserLocation = true

        

        if (self.mapView?.userTrackingMode != MAUserTrackingMode.Follow) {

            

            self.mapView?.setUserTrackingMode(MAUserTrackingMode.Follow, animated: true)

            

        }

        

    }

    

//    //设备更新后调用此接口

//    func mapView(mapView: MAMapView!, didUpdateUserLocation userLocation: MAUserLocation!, updatingLocation: Bool) {

//        

//        if (updatingLocation) {

//            

//            //取出当前位置的坐标

//            print(userLocation.title)

//            

//            self.searchReGeocodeWithCoordinate(userLocation.coordinate)

//            

//            print(userLocation.coordinate.longitude)

//            

//        }

//        

//        

//    }

//    

//    //逆地理编码

//    func searchReGeocodeWithCoordinate(coordinate:CLLocationCoordinate2D!) {

//    

//        let rego : AMapReGeocodeSearchRequest = AMapReGeocodeSearchRequest()

//        

//        rego.location = AMapGeoPoint.locationWithLatitude(CGFloat(coordinate.latitude), longitude: CGFloat(coordinate.longitude))

//        

//        rego.requireExtension = true

//        

//        self.search!.AMapReGoecodeSearch(rego)

//    

//    

//    }

//    

//    //逆地理编码回调

//    func onReGeocodeSearchDone(request: AMapReGeocodeSearchRequest!, response: AMapReGeocodeSearchResponse!) {

//        

//        if (response.regeocode != nil) {

//            

//           // var tmp : AMapPOI = response.regeocode.pois .first

//            

//            var tddd : AMapAddressComponent = response.regeocode.addressComponent

//            

//            self.tmpcity = tddd.city

//            

//            self.mapView?.showsUserLocation = false

//            

//        }

//        

//        

//        

//    }

    

    //定位失败时调用

    

    func mapView(mapView: MAMapView!, didFailToLocateUserWithError error: NSError!) {

        

        let status : CLAuthorizationStatus = CLLocationManager.authorizationStatus()

        

        if (CLLocationManager.authorizationStatus() == .Denied || CLLocationManager.authorizationStatus() == .Restricted) {

            

            var alret : UIAlertView = UIAlertView.init(title: "", message: "请开启定位功能,才能更好的为您服务", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "设置", "")

            alret.tag = 201

            

            alret.show()

            

        }

        

        

        

    }

    

    func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {

        

        if (alertView.tag == 201) {

            

            if (buttonIndex == 1) {

                

                //UIApplication.sharedApplication().openURL(NSURL(string: link)!)

                

                if #available(iOS 8.0, *) {

                    UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)

                } else {

                    

                    print("定位关闭,不可用")

                    

                }

                

            }

            

        }

        

        

    }

    

    

    

    

       


    /*

    // MARK: - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        // Get the new view controller using segue.destinationViewController.

        // Pass the selected object to the new view controller.

    }

    */


}



extension MoveCarViewController:UIActionSheetDelegate {

    

    func actionSheet(actionSheet:UIActionSheet,clickedButtonAtIndex buttonIndex: Int) {

        

        let picker = UIImagePickerController()

        

        picker.delegate = self

        

        if buttonIndex == 0 {

            

            return

            

        }else if buttonIndex == 1 {

            

            picker.sourceType = .Camera

            

        }else {

            

            picker.sourceType = .PhotoLibrary

            

        }

        

        presentViewController(picker, animated: true) { () -> Void in

            

            UIApplication.sharedApplication().statusBarStyle = .Default

            

        }

        

    }

    

}





extension MoveCarViewController :UIImagePickerControllerDelegate,UINavigationControllerDelegate {

    

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        

        UIApplication.sharedApplication().statusBarStyle=UIStatusBarStyle.LightContent

        

        self.dismissViewControllerAnimated(true, completion: nil)

        

        //存储照片

        var headImage : UIImage?

        

        headImage = info[UIImagePickerControllerOriginalImage] as? UIImage

        

        headImage = MyImageHandle.imageWithImageSimple(headImage, scaledToSize: CGSizeMake(120, 120))

        

        let nameStr : String = Guid.share().getGuid()

        

        saveImage(headImage!, name: "\(nameStr).png")

        

        imageFileStr = "\(AppSetting.PicturePath)\(nameStr).png"

        

        print(imageFileStr)

        

        

            

            //ImageButton.setImage(UIImage(contentsOfFile: imageFileStr!), forState: .Normal)

        

        ImageButton.setBackgroundImage(UIImage(contentsOfFile:imageFileStr!), forState: .Normal)

        

    }

    func saveImage(image:UIImage,name:String){

        

        let KCompressionQuality : CGFloat = 1

        

        let imageData : NSData = UIImageJPEGRepresentation(image,KCompressionQuality)!

        

        

        if NSFileManager.defaultManager().fileExistsAtPath(AppSetting.PicturePath) == false{

            

            try! NSFileManager.defaultManager().createDirectoryAtPath(AppSetting.PicturePath, withIntermediateDirectories: true, attributes: nil)

            

        }

        

        let sss : Bool = imageData.writeToFile("\(AppSetting.PicturePath)\(name)", atomically: false)

        

        print(sss)

        

        

    }

    

}







相关文章:

万字干货 | Python后台开发的高并发场景优化解决方案

嘉宾 | 黄思涵 来源 | AI科技大本营在线公开课互联网发展到今天&#xff0c;规模变得越来越大&#xff0c;也对所有的后端服务提出了更高的要求。在平时的工作中&#xff0c;我们或多或少都遇到过服务器压力过大问题。针对该问题&#xff0c;本次公开课邀请到了金山办公AI平台研…

提高C++性能的编程技术笔记:引用计数+测试代码

引用计数(reference counting)&#xff1a;基本思想是将销毁对象的职责从客户端代码转移到对象本身。对象跟踪记录自身当前被引用的数目&#xff0c;在引用计数达到零时自行销毁。换句话说&#xff0c;对象不再被使用时自行销毁。 引用计数和执行速度之间的关系是与上下文紧密…

如何提升 CSS 选择器的性能?

CSS选择器对性能的影响源于浏览器匹配选择器和文档元素时所消耗的时间&#xff0c;所以优化选择器的原则是应尽量避免使用消耗更多匹配时间的选择器。而在这之前我们需要了解CSS选择器匹配的机制&#xff0c; 如子选择器规则&#xff1a; #header > a {font-weight:blod;} 我…

百度AI攻坚战:PaddlePaddle中国突围

作者 | 阿司匹林出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;2013年&#xff0c;百度开始研发深度学习框架PaddlePaddle&#xff0c;搜索、凤巢CTR预估上线DNN模型。2016年&#xff0c;在百度世界大会上&#xff0c;百度宣布PaddlePaddle开源&#xff…

提高C++性能的编程技术笔记:编码优化+测试代码

缓存&#xff1a;在现代处理器中&#xff0c;缓存经常与处理器中的数据缓存和指令缓存联系在一起。缓存主要用来存储使用频繁而且代价高昂的计算结果&#xff0c;这样就可以避免对这些结果的重复计算。如&#xff0c;循环内对常量表达式求值是一种常见的低性能问题。 预先计算…

Swift 中使用 SQLite——打开数据库

关于Swift中使用SQLite&#xff0c;接下来可能会分别从打开、增、删、改、查&#xff0c;几个方面来介绍SQLite的具体使用&#xff0c;这一篇重点介绍一下如何打开。 定义全局数据库访问句柄 /// 全局数据库访问句柄 private var db: COpaquePointer nil实现打开数据库函数 …

MVC中获取模型属性的Range和StringLength验证特性设置

MVC中的客户端及服务端模型验证信息都以ModelMetadata类型作为承载&#xff0c;在获得属性的ModelMetadata之后&#xff08;还不知道怎么获取ModelMetadata的童鞋请自行恶补&#xff09;&#xff0c;我们可以轻松得到一些我们在模型中定义的特性&#xff0c;比如显示名称、是否…

以安装PyTorch为例说明Anaconda在Windows/Linux上的使用

在Windows10上配置完MXNet 1.3.0后&#xff0c;再配置PyTorch 1.0时&#xff0c;发现两者需要依赖的NumPy版本不一致&#xff0c;之前是通过pip安装NumPy&#xff0c;根据pip的版本不同&#xff0c;会安装不同版本的NumPy&#xff0c;使用起来很不方便&#xff0c;而且MXNet和P…

常用 SQL介绍

创建表 /*创建数据表CREATE TABLE 表名 (字段名 类型(INTEGER, REAL, TEXT, BLOB)NOT NULL 不允许为空PRIMARY KEY 主键AUTOINCREMENT 自增长,字段名2 类型,...)注意&#xff1a;在开发中&#xff0c;如果是从 Navicat 粘贴的 SQL&#xff0c;需要自己添加一个指令IF NO…

AttoNets,一种新型的更快、更高效边缘计算神经网络

作者 | Alexander Wong, Zhong Qiu Lin, and Brendan Chwyl 译者 | Rachel 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;尽管机器学习已经在很多复杂的任务中取得了进展&#xff0c;但现有模型仍然面临许多边缘计算实践的困难&#xff0c;这些边缘计算场景包括移…

Appro DM8127 IPNC 挂载NFS遇到的问题及解决

对于Appro DM8127 IPNC&#xff0c;默认的启动方式是NAND is used for booting kernel and NAND is used as root filesystem 为了调试应用程序方便&#xff0c;通常使用挂载NFS作为 root filesystem 但是如果直接采用ti文档中所给的方法修改文件系统挂载方式&#xff08;将启动…

提高C++性能的编程技术笔记:设计优化/可扩展性/系统体系结构相关+测试代码

1. 设计优化 我们可以粗略地将性能优化分为两种类型&#xff1a;编码优化和设计优化。编码优化定义为不需要完整理解要解决的问题或者应用程序的执行流程就能实施的优化。通过定义看出&#xff0c;编码优化用于局部代码&#xff0c;同时该过程不牵涉周围的代码。除了这些容易实…

ICLR 2020被爆半数审稿人无相关领域经验,同行评审制度在垮塌?

作者 | 若名出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;根据维基百科&#xff0c;同行评议&#xff08;peer review)&#xff0c;是指由一个或多个具有与作品生产者具有相似能力的人员&#xff08;同行&#xff09;对作品进行的评估活动。同行评审方法用于维持质…

Swift 中使用 SQLite——批量更新(事务处理)

本文是Swift 中使用 SQLite系列的收官之作&#xff0c;介绍一下在数据库中的批量更新。 事务 在准备做大规模数据操作前&#xff0c;首先开启一个事务&#xff0c;保存操作前的数据库的状态开始数据操作如果数据操作成功&#xff0c;提交事务&#xff0c;让数据库更新到数据操…

网络管理常用命令之二 - Ipconfig 命令详解(图文)

2、Ipconfig 命令...不带参数.../all 参数.../release 和 /realease6 参数.../Renew 和 /Renew6 参数.../flushdns 参数.../displaydns 参数2、Ipconfig 命令 ipconfig命令也是使用率非常高的一个命令&#xff0c;可用于显示系统的TCP/IP网络配置值&#xff0c;并刷新动态主…

Swift 中使用 SQLite——查询数据

本文主要介绍如何查询 SQLite 结果集&#xff0c;以及封装 SQLite 的操作方法。 准备测试代码 /// 从数据库中加载 person 数组 class func persons() -> [Person]? {// 1. 准备 SQLlet sql "SELECT id, name, age, height FROM T_Person;"// 2. 访问数据库// …

提高C++性能的编程技术笔记:总结

《提高C性能的编程技术》这本书是2011年出版的&#xff0c;书中有些内容的介绍可能已经过时&#xff0c;已不再适用于现在的C编程中&#xff0c;但大部分内容还是很有参考意义的。 这里是基于之前所有笔记的简单总结&#xff0c;笔记列表如下&#xff1a; 跟踪实例&#xff1…

13岁小孩都跟我抢Python了,完了!

以下来自一位程序员母亲和工作人员的对话。程序员妈妈&#xff1a;您好&#xff0c;可以帮我推荐一本适合我家小孩看的编程书籍吗&#xff1f;兔子&#xff1a;可以的呀&#xff0c;《Scratch从入门到精通》&#xff0c;这本书适合小孩学习&#xff0c;您可以先看一下哦~程序员…

Windows Mobile 6.0 SDK和中文模拟器下载

【转】 Windows Mobile 6.0 SDK和中文模拟器下载 Windows Mobile 6.5 模拟器2010年12月06日 星期一 07:48转载自 zhangyanle86终于编辑 zhangyanle86Windows Mobile 6.0 SDK和中文模拟器下载 SDK 6.0下载页面&#xff1a;http://www.microsoft.com/downloads/details.aspx?fam…

wxPython:Python首选的GUI库 | CSDN博文精选

作者 | 天元浪子来源 | CSDN博客文章目录概述窗口程序的基本框架事件和事件驱动菜单栏/工具栏/状态栏动态布局AUI布局DC绘图定时器和线程后记概述跨平台的GUI工具库&#xff0c;较为有名的当属GTK、Qt 和 wxWidgets 了。GTK是C实现的&#xff0c;由于C语言本身不支持OOP&#x…

Swift 中使用 SQLite——修改和删除数据

本文主要介绍在SQLite中修改数据、删除数据&#xff1a; 更新记录 /// 将当前对象信息更新到数据库 /// /// - returns: 是否成功 func updatePerson() -> Bool {guard let name name else {print("姓名不能为空")return false}if id < 0 {print("id 不…

用python3实现指定目录下文件sha256及文件大小统计

有时会统计某个目录下有哪些文件&#xff0c;每个文件的sha256及文件大小等相关信息&#xff0c;这里用python3写了个脚本用来实现此功能&#xff0c;此脚本可跨平台&#xff0c;同时支持windows和linux&#xff0c;脚本(get_dir_file_info.py)内容如下&#xff1a; import os…

Swift 中使用 SQLite——新增数据

本文重点介绍两个方面&#xff0c;1、新增数据&#xff0c;2、获取自动增长 ID。 建立 Person.swift 数据模型 /// 个人模型 class Person: NSObject {// MARK: - 模型属性/// 代号var id: Int64 0/// 姓名var name: String?/// 年龄var age 0/// 身高var height: Double …

投稿2877篇,EMNLP 2019公布4篇最佳论文

整理 | AI科技大本营&#xff08;ID:rgznai100&#xff09;近日&#xff0c;自然语言处理领域的顶级会议之一EMNLP 2019公布了年度最佳论文。EMNLP是由国际语言学会&#xff08;ACL&#xff09;下属的SIGDAT小组主办的自然语言处理领域的顶级国际会议&#xff0c;是自然语言算法…

对象检测工具包mmdetection简介、安装及测试代码

mmdetection是商汤和港中文大学联合开源的基于PyTorch的对象检测工具包&#xff0c;属于香港中文大学多媒体实验室open-mmlab项目的一部分。该工具包提供了已公开发表的多种流行的检测组件&#xff0c;通过这些组件的组合可以迅速搭建出各种检测框架。 mmdetection主要特性&am…

(转)eclipse 代码自动补全

转自&#xff1a;http://blog.csdn.net/yushuwai2010/article/details/11856129 一般默认情况下&#xff0c;Eclipse的代码提示功能是比MicrosoftVisualStudio的差很多的&#xff0c;主要是Eclipse本身有很多选项是默认关闭的&#xff0c;要开发者自己去手动配置。如果开发者不…

swift 多线程GCD和延时调用

GCD 是一种非常方便的使用多线程的方式。通过使用 GCD&#xff0c;我们可以在确保尽量简单的语法的前提下进行灵活的多线程编程。在 “复杂必死” 的多线程编程中&#xff0c;保持简单就是避免错误的金科玉律。好消息是在 Swift 中是可以无缝使用 GCD 的 API 的&#xff0c;而且…

目标检测算法Faster R-CNN简介

在博文https://blog.csdn.net/fengbingchun/article/details/87091740 中对Fast R-CNN进行了简单介绍&#xff0c;这里在Fast R-CNN的基础上简单介绍下Faster R-CNN。 目标检测领域从R-CNN开始&#xff0c;通过引入卷积神经网络取得了很多突破性的进展&#xff0c;但是始终未能…

ICCV 2019 | 加一个任务路由让数百个任务同时跑起来,怎么做到?

作者 | Gjorgji Strezoski, Nanne van Noord, Marcel Worring 译者 | 中国海洋大学李杰 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;摘要传统的多任务&#xff08;MTL&#xff09;学习方法依赖于架构调整和大型可训练参数集来联合优化多个任务。但是&#xff0c;…

DEV开发之控件NavBarControl

右键点击RunDesigner弹出如下界面鼠标先点击3或4,1&#xff0c;&#xff0c;然后点击1或2进行相应的新增或删除操作&#xff0c;3是分组&#xff0c;4是项目&#xff0c;4可以直接拖动到相应的分组3.属性caption:显示的名称4.NavBarControl 属性 PaintStyleName绘画风格&…