Giter Site home page Giter Site logo

map-with-car-ios's Introduction

map-with-car-ios

This is an investigation of how to build moving/rotating car (similar to Uber app)

Tasks solved

  • show annotation with custom icon (Car in our case)
  • calculate direction (aka bearing) between 2 points on map (based on Haversine formla)
  • rotate car icon correspondingly
  • zoom map to always show both user and car
  • "random" locations generator logic was added in order to test "moving car" (new location is generated from the previous one with distance between 0..100m and bearing betweeen 0..360 degrees)

Demo image

Project structure

  • ViewController is responsible for showing map, being MapDelegate and handling IBActions
  • CarLocationService is responsible for generating, providing and storing car locations
  • MapDrawUtil is responsible for drawing objects on the map (e.g. car, car route)
  • MyLocationManager is responsible for handling location permissions and location updates
  • Different extensions are used as utils for random data generation, custom calculations

Pitfalls

  • Car icon rotation is a bit tricky. Direction/Bearing is based on compass and North is 0°, while rotation goes clockwise (e.g. East is 90°, South is 180°, West is 270°). While image rotation happens counter-clockwise with 0° equal to original image rotation. To apply rotation for the car image the angle should be "inverted" like 360 - direction.

Compass based direction

  • Image rotation is not trivial either, separate extension was created in order to do that. Image quality can be impacted by rotation algoritm.

  • zooming map to contain all the coordinates (e.g. user and car) is a bit tricky as well.

map-with-car-ios's People

Contributors

sergii-frost avatar

Watchers

 avatar  avatar

Forkers

vikas100

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.