1.下载Google map的sdk,详情参考:

Get Started

2.准备好SDK后,展示map这些问题都不大,稍微难点的是定位当前位置

可以参考google的git tutorial:

https://github.com/googlemaps/maps-sdk-for-ios-samples/tree/master/tutorials

同时可以参考:

iOS之集成GoogleMap(定位、搜索)需要注意的事:http://www.cocoachina.com/cms/wap.php?action=article&id=21868
3.我的示例代码:
import UIKit
import GoogleMaps
import GooglePlaceslet screenH = UIScreen.main.bounds.size.height
let screenW = UIScreen.main.bounds.size.widthclass BookController: UIViewController,UITableViewDelegate,UITableViewDataSource {//MARK:UI widget@IBOutlet weak var googleMapView: UIView!@IBOutlet weak var merchantTable: UITableView!@IBOutlet weak var searchBarView: UIView!//MARK:Othersvar merchantList: Array<MerchantBookDetail> = []//MARK: Google mapvar placesClient: GMSPlacesClient!var locationManager = CLLocationManager()var currentLocation: CLLocation?var mapView: GMSMapView?var zoomLevel: Float = 16.0// An array to hold the list of likely places.var likelyPlaces: [GMSPlace] = []// The currently selected place.var selectedPlace: GMSPlace?// A default location to use when location permission is not granted.let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.199)override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.initData()initView()}func initData()  {merchantList = initMerchant()placesClient = GMSPlacesClient.shared()// Initialize the location manager.locationManager = CLLocationManager()locationManager.desiredAccuracy = kCLLocationAccuracyBestlocationManager.requestAlwaysAuthorization()locationManager.distanceFilter = 50locationManager.startUpdatingLocation()locationManager.delegate = self}func initView()  {loadGoogleMap()//tablemerchantTable.delegate = selfmerchantTable.dataSource = selfmerchantTable.separatorStyle = UITableViewCellSeparatorStyle.none}func initMerchant() -> Array<MerchantBookDetail> {let merchant_one = MerchantBookDetail(merchant: "般咸道35号地下\n电话:2297 3377")let merchant_two = MerchantBookDetail(merchant: "尖沙咀金马伦道12号\n恒信商业大厦l字全层\n电话:3422 8855")let merchantList : [MerchantBookDetail] = [merchant_one,merchant_two];return merchantList}// Update the map once the user has made their selection.@IBAction func unwindToMain(segue: UIStoryboardSegue) {// Clear the map.mapView?.clear()// Add a marker to the map.if selectedPlace != nil {let marker = GMSMarker(position: (self.selectedPlace?.coordinate)!)marker.title = selectedPlace?.namemarker.snippet = selectedPlace?.formattedAddressmarker.map = mapView}listLikelyPlaces()}// Populate the array with the list of likely places.func listLikelyPlaces() {// Clean up from previous sessions.likelyPlaces.removeAll()placesClient.currentPlace(callback: { (placeLikelihoods, error) -> Void inif let error = error {// TODO: Handle the error.print("Current Place error: \(error.localizedDescription)")return}// Get likely places and add to the list.if let likelihoodList = placeLikelihoods {for likelihood in likelihoodList.likelihoods {let place = likelihood.placeself.likelyPlaces.append(place)}}})}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}@IBAction func selectBtnAction(_ sender: Any) {let bookSelectVC:BookSelectController = UIStoryboard.init(name: "Book", bundle: nil).instantiateViewController(withIdentifier: "book-select") as! BookSelectControllerself.navigationController?.pushViewController(bookSelectVC, animated: true)}func loadGoogleMap() {// Create a GMSCameraPosition that tells the map to display thelet camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude,longitude: defaultLocation.coordinate.longitude,zoom: zoomLevel)let rect = CGRect(x: 0, y: 0, width: googleMapView.frame.width, height: googleMapView.frame.height)mapView = GMSMapView.map(withFrame: rect, camera: camera)mapView?.settings.myLocationButton = truemapView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]mapView?.isMyLocationEnabled = truemapView?.settings.compassButton = truegoogleMapView.backgroundColor = UIColor.clear// Add the map to the view, hide it until we've got a location update.googleMapView.addSubview(mapView!)
//        mapView?.isHidden = truelistLikelyPlaces()googleMapView.addSubview(searchBarView)}func safeAreaInsetmap(view: UIView) -> UIEdgeInsets {if #available(iOS 11, *) {return view.safeAreaInsets}return UIEdgeInsets.zero}//MARK:table view APIfunc tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return merchantList.count}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {let row = indexPath.rowlet cellId = "book_map_cell"let cell: BookMapTableCellTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! BookMapTableCellTableViewCelllet merchant = merchantList[row]cell.merchantDetail.text = merchant.merchantDetailcell.merchantImage.image = UIImage.init(named: "merchantImage_\(row+1)")return cell}
}// Delegates to handle events for the location manager.
extension  BookController: CLLocationManagerDelegate {// Handle incoming location events.func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {let location: CLLocation = locations.last!print("Location: \(location)")let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,longitude: location.coordinate.longitude,zoom: zoomLevel)let position2D = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)let marker = GMSMarker(position: position2D)marker.map = self.mapViewif (mapView?.isHidden)! {mapView?.isHidden = falsemapView?.camera = camera} else {mapView?.animate(to: camera)}listLikelyPlaces()}// Handle authorization for the location manager.func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {switch status {case .restricted:print("Location access was restricted.")case .denied:print("User denied access to location.")// Display the map using the default location.mapView?.isHidden = falsecase .notDetermined:print("Location status not determined.")case .authorizedAlways: fallthroughcase .authorizedWhenInUse:print("Location status is OK.")}}// Handle location manager errors.func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {locationManager.stopUpdatingLocation()print("Error: \(error)")}
}

[IOS]整合google map并获取当前位置相关推荐

  1. android google map v2 获取当前位置,如何在google map v2中获取当前位置信息?

    代码来获得用户 public void getMyLocation(Activity activity) { int requestPermissionsCode = 50; LocationMana ...

  2. iOS学习之Map,定位,标记位置的使用

    iOS上使用地图比Android要方便,只需要新建一个MKMapView,addSubView即可.这次要实现的效果如下: 有标注(大头针),定位,地图. 1.添加地图 1.1 新一个Single V ...

  3. 利用HTML5中Geolocation获取地理位置在Google Map上定位

    本小菜刚开始学习HTML5,现在对其中的Geolocation颇感兴趣,结合Google Map的API实现基本的地图定位功能. 1.获取当前地理位置 调用方法 void getCurrentPosi ...

  4. google map for ios聚合

    google map for ios聚合 必须番羽墙才可以用google map,不管是android手机还是ios,都需要番羽墙才可用....并且android手机还需要装google服务框架 io ...

  5. Google Map开发之实战

    视频课:[免费]跨平台APP JQuery Mobile开发-1-初探移动开发-张晨光的在线视频教程-CSDN程序员研修院 学习内容 Google Map服务简介 获取Google Map API K ...

  6. 从零开始学google地图API(5)--粗略获取当前位置

    之前研究过一段时间的定位 当时没学过html,javascript,也不懂背后的原理 只知道用一些软件,比如说trape等等 现在学了google地图后,可以借助 navigator.geolocat ...

  7. iOS 10下Webkit如何获取位置信息?

    iOS 10正式版将会在9月13日推出,也就是国内的时间9月14日凌晨1点.率先体验过iOS 10的开发者们可能会发现这样一个问题,就是WebKit下的网页会出现无法获取到位置信息的现象. 例如下面这 ...

  8. iOS UITableView获取特定位置的cell

    代码地址如下: http://www.demodashi.com/demo/13307.html 一.tableView双级联动 以上两种效果比较类似,实现的关键在于都是需要获得在滑动过程中滑动到ta ...

  9. Google Map API v2 (三)----- 地图上添加标记(Marker),标记info窗口,即指定经纬度获取地址字符串...

    接上篇 http://www.cnblogs.com/inkheart0124/p/3536322.html 1,在地图上打个标记 1 private MarkerOptions mMarkOptio ...

最新文章

  1. Opencv笔记(九)——图像阈值
  2. win10安装oracle 11g最新亲身经历操作记录
  3. 菜鸟级WEX5开发之路【用B/S开发经验应用到WEX5的开发中来】
  4. css两列布局之基于BFC规则实现
  5. Angular应用里的@Input和@Output注解使用方法介绍
  6. Java笔记-Spring Boot JDBC连接Oracle数据库
  7. 8.1、Spring Boot 属性配置
  8. 智能优化算法:黑寡妇算法 -附代码
  9. java项目 服务器部署Word转成PDF乱码
  10. VB6.0 与 VS2010 在VB编程上的区别小总结
  11. 相见恨晚 linux下的c++filt 命令
  12. excel怎么设置打印区域_彩色打印机怎么设置默认打印黑白色?
  13. 不能整除7的整数C语言,求1-1000中能被3整除,且不能被7整除,且至少有一位数是5的整数...
  14. ospf路由器连接物理网络的方式 以及ospf与IGRP对比(补充)
  15. 巴旦木即将成为农业的下一个“风口”河南巴旦木生态农业:值得期待
  16. esxi远程管理端口_如何在 vmware esxi 中开放 VNC功能及端口实现远程管理 完整篇...
  17. 代数合并同类项计算机步骤,代数式(合并同类项)
  18. 怎么下载地质图、专题图等其它专业地图
  19. 720P、1080P、4K之间有什么区别和联系?
  20. 肠道菌群检测在临床感染判别中的应用

热门文章

  1. 解决crx文件扩展程序chrome下载自动删除的问题
  2. 浅谈![CDATA[ ]]
  3. 威廉.布莱克 和 他的诗歌
  4. HTML5讲解与演示转载整理
  5. 电脑win10蓝屏,INACCESSIBLE BOOT DEVICE,处理方法
  6. linux面试题_全网最新、最全Linux面试题(2020版)!
  7. 说得清的Epoll原理
  8. 写给大忙人的模电复习资料(001)
  9. 读书笔记:卓有成效的管理者
  10. 《卓有成效的管理者》——学习心得(二)