Google Map定位,大头针(Swift3.0)
来源:互联网 发布:汕头酒店美工招聘 编辑:程序博客网 时间:2024/06/06 14:21
1.cocoapods集成Google Map SDK
platform :ios, '8.1'
use_frameworks!
target 'GoogleMapTest'do
pod 'GoogleMaps'
end
2.plist文件配置
1>LSApplicationQueriesSchemes array
item1 googlechromes
item2 comgooglemaps
2>App Transport Security Settings
Allow Arbitrary Loads YES
3>Privacy - Location Always Usage Description
4>Privacy - Location When In Use Usage Description
3.代码
import UIKit
import GoogleMaps
import CoreLocation
class WeizhiViewController:UIViewController,CLLocationManagerDelegate {
let locationManager =CLLocationManager()
var currentLocation:CLLocation!
var lock =NSLock()
overridefunc viewDidLoad() {
super.viewDidLoad()
locationManager.delegate =self
locationManager.desiredAccuracy =kCLLocationAccuracyBest //定位精确度(最高)一般有电源接入,比较耗电
//kCLLocationAccuracyNearestTenMeters;//精确到10米
locationManager.distanceFilter =50 //设备移动后获得定位的最小距离(适合用来采集运动的定位)
locationManager.requestWhenInUseAuthorization()//弹出用户授权对话框,使用程序期间授权(ios8后)
//requestAlwaysAuthorization;//始终授权
locationManager.startUpdatingLocation()
print("开始定位》》》")
}
overridefunc didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//委托传回定位,获取最后一个
func locationManager(_ manager:CLLocationManager, didUpdateLocations locations: [CLLocation]) {
lock.lock()
currentLocation = locations.last //注意:获取集合中最后一个位置
print("定位经纬度为:\(currentLocation.coordinate.latitude)")
//一直发生定位错误输出结果为0:原因是我输出的是currentLocation.altitude(表示高度的)而不是currentLoction.coordinate.latitude(这个才是纬度)
print(currentLocation.coordinate.longitude)
lock.unlock()
//跳转Google Map
let camera =GMSCameraPosition.camera(withLatitude:currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude, zoom:12)
//大头针标记
let coordinate = CLLocationCoordinate2D(latitude:currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
setuplocationMarker(coordinate: coordinate)
let mapView =GMSMapView.map(withFrame:CGRect.zero, camera: camera)
self.view = mapView
}
//大头针设置的一些参数
func setuplocationMarker(coordinate:CLLocationCoordinate2D) {
locationMarker =GMSMarker(position: coordinate)
locationMarker.map =self.viewas! GMSMapView?
locationMarker.title ="sasdw"
locationMarker.appearAnimation =kGMSMarkerAnimationPop
locationMarker.icon =GMSMarker.markerImage(with:UIColor.blue)
locationMarker.opacity =0.75
}
func locationManager(_ manager:CLLocationManager, didFailWithError error:Error) {
print("定位出错拉!!\(error)")
}
}
4.调试
真机调试,由于Google map需要翻墙才能使用,所以手机上也必须连接VPN,才可以使用
- Google Map定位,大头针(Swift3.0)
- iOS大头针(自定义大头针,定位,画线)
- iOS定位添加大头针
- iOS地图和定位服务(自定义大头针)
- 地图与定位(三)自定义大头针视图
- swift地图定位(十二)大头针的基本使用
- swift地图定位(十三)大头针系统视图
- swift地图定位(十四)使用 MKAnnotationView自定义大头针视图
- 利用基站定位Use Google Map
- Android用户定位Google Map显示地图
- google Map API根据坐标点定位
- 解决google map无法网络定位问题
- Google Map API v2的定位
- google map定位的简单实例
- Google Map开发系列(六)——谷歌地图坐标定位
- swift3.0之后改变的语法 二维码定位
- 高德地图的定位和大头针
- google map api3.0
- jsp中使用EL表达式并且在js中使用该值需要注意的地方
- CXF webService集成spring
- HelloChart--PieChartView(饼图)
- android程序报错:error:Error:String types not allowed(at 'configChanges' with value '
- android 通知栏图标变白色方格
- Google Map定位,大头针(Swift3.0)
- iOS 推送全解析,你不可不知的所有 Tips!(完整版)
- GitLab: You are not allowed to push code to protected branches on this project.
- android 基础 res文件 drawable
- POJ 2288 Islands and Bridges
- JS实现密码加密
- HTTP协议详解
- Android TextView实现跑马灯效果
- Linux 命令(文件和目录管理 - more/less)