GithubHelp home page GithubHelp logo

twho / map-loader-ios Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 61.8 MB

Quickly loads iOS and Google maps, customized annotations and clusters

Home Page: https://cocoapods.org/pods/MapLoader

License: MIT License

Ruby 9.11% Swift 89.57% Objective-C 1.33%
ios googlemaps applemaps markers annotations clustering clusters swift google-maps-api

map-loader-ios's Introduction

MapLoader-iOS

Swift 4.0 iOS 10.0+ Version License Platform

MapLoader is a tool helps you quickly loads Google and/or Apple maps on iOS. In addition, the library includes highly-customized annotations, markers and clusters views that allows you to design your own map UI.

You may download MapLoaderDemo to see how its used in your app.

Key Features

  • Easily loads Google and Apple maps on iOS
  • Customizable markers and annotations
  • Built-in foreground and background images for markers and annotations
  • Clustering markers and annotations
  • Markers and annotations animation support

Requirements

  • Swift 4.0
  • iOS 10.0+

Usage

Follow the instructions below to quickly setup MapView.

Step 1: Initialize a MapLoader object

let mapLoader = MapLoader()

Initialize a GoogleMapLoader object

let mapLoader = GoogleMapLoader()
  • Note: You need to set API key in AppDelegate.swift before having access to Google map, see Supplementals for more details.

Step 2: Insert view to your current view in viewWillAppear() function

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    mapLoader.setupMapView(mapContainer: self.view, viewAboveMap: nil, delegate: self)
}
  • Note: You need to set delegate if you need to use MKMapViewDelegate. Otherwise, you can leave it nil

Step 3: Resize the MapView in viewDidLayoutSubviews() function

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    mapLoader.layoutMapView()
}

Follow the instructions below to use clusters and annotations/markers.

Step 4: Add your customized annotations

  • Use StyledAnnotationView for annotation views

var annotations: [MLAnnotation] = []  
let annotView = StyledAnnotationView(annotImg: .hazard, color: UIColor.white, background: .bubble, bgColor: UIColor.blue)
let annotation = MLAnnotation(coordinate: CLLocationCoordinate2D(latitude: 42.36, longitude: -71.06), annotView: annotView, data: nil)  
annotations.append(annotation)  
mapLoader.addAnnotations(annotations: annotations)
  • Simply change the object to MLMarker for Google map use

let annotation = MLMarker(coordinate: CLLocationCoordinate2D(latitude: 42.36, longitude: -71.06), annotView: annotView, data: nil)  

Step 5: Setup MKMapViewDelegate and use the following functions.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    return mapLoader.generateClusteringView(annotation: annotation) as? MKAnnotationView
}

Step 6: Refresh annotations and clusters when MapView region is changed

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    return mapLoader.generateClusteringView(annotation: annotation) as? MKAnnotationView
}

func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
    mapLoader.refreshMap()
}
  • Google map use GMSMapViewDelegate

Refresh the map after users finish their gestures.

func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
    mapLoader.refreshMap()
}

Supplementals

  • Use your own image as annotation view

let image = UIImage(named: "your_image")
let annotView = StyledAnnotationView(annotImg: image, background: .bubble, bgColor: UIColor.blue)
  • Built-in annotation-like background images available.

/**
Built-in background images.

- bubble: bubble background
- square: square-shaped background
- circle: circular background
- heart:  heart-shaped background
- flag:   flag background
*/
public enum BgImg {
    case bubble
    case square
    case circle
    case heart
    case flag
}
  • Set Google map API key in AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    GoogleMapLoader.setAPIKey("YOUR_API_KEY")
    return true
}

Installation

MapLoader is available through CocoaPods. To install it, simply add the following line to your Podfile:

$ pod 'MapLoader'

If you don't use CocoaPods, you can download the entire project then drag and drop all the classes and use them in your project.

Credits

map-loader-ios's People

Contributors

michael-ho-bose avatar twho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sevinaysharma

map-loader-ios's Issues

GMSMapViewDelegate didn't call in embed UIViewController

Hi! Thank you for making map-loader-ios
It's convenient to add custom annotations.
I add GMSMapView in embedded UIViewController.
I made UITabbarController. SecondVC included in tabbarcontroller.
The problem is GMSMapViewDelegate didn't call it.

I just put selfvariable on code.

class RandomMapVC: UIViewController, UINavigationControllerDelegate {
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        mapLoader.setupMapView(mapContainer: self.view, viewAboveMap: navigationController?.view, delegate: self)
        mapLoader.isLocationButtonShown = true
        refreshMap()
    }

}

GMSMapView didn't work on Zoom and move.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.