Coder Social home page Coder Social logo

react-apple-mapkitjs's Introduction

react-apple-mapkitjs

Installation

npm install react-apple-mapkitjs

Add the script file in your reacts public index.html file

<script src="https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js"></script>

Getting an access token to use Apple's mapkitjs

Getting your token to get mapkitjs to work is not the most simple of tasks, I recommend watching this video in full to understand how to do this. https://developer.apple.com/videos/play/wwdc2018/508

If you want a simpler explanation and dont mind giving your private key to some other app to create your access token then the following link is a great resource. https://mapkitjs.rubeng.nl/#/


Once you have your access token

Import the AppleMaps component into your project

    import { AppleMaps } from 'react-apple-mapkitjs'

The only prop that is required is the token prop, without this you will get a "initialization failed" in the console
    <AppleMaps 
        token="your access token here"
    />

If the access token is correct then the map will default to Leeds, UK


Additional props and components

The AppleMaps component takes additional props to adjust the map view and zoom level, you can also specify a map width and height. It currently defaults to view height and width.

    <AppleMaps
        token="your access token here"
        longitude={30.8008}
        latitude={-1.5491}
        zoomLevel={1}
        height='100px'
        width='100px'
    />

You can also use additional Annotation components to put customizable drop pins on your apple map. The Annotation Components must be child components of AppleMaps.

First import both the AppleMaps and the Annotation component

import { AppleMaps, Annotation, ImageAnnotation } from 'react-apple-mapkitjs'

then add to your react application

<AppleMaps
    token="your access token here"
    longitude={53.8008}
    latitude={-1.5491}
    zoomLevel={6}
>
    <Annotation 
        longitude={53.8158}
        latitude={-1.6017}
        color="#969696"
        title="Apple"
        subtitle="work"
        selected={true}
        glyphText=""
    />
    <Annotation 
        longitude={53.8158}
        latitude={-1.5017}
        color="#349576"
        title="New Annotation"
        subtitle="work"
        selected={false}
    />
    <ImageAnnotation 
        longitude={53.8158}
        latitude={-1.4017}
        title="Cat Cafe"
        subtitle="scholes"
        selected={false}
        url='./assets/cat.jpeg'
        visible={false}
    />
</AppleMaps>

Most of the props to the Annotation component are self explanatory


Common Issues

Map not visible but no console errors - Set the width and height of the map as it may be rendering at 0px x 0px


Future Development

I'm going to carry on developing this component as it currently only has basic functionality, if there are any requests or you need any anymore help than that provided above then feel free to get in touch

react-apple-mapkitjs's People

Contributors

dependabot[bot] avatar fabiankaegy avatar lucidlemon avatar tonyduanesmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-apple-mapkitjs's Issues

Allow specifying the maptype to be shown

I would love to be able to set the maptypes through props:

<AppleMaps
    mapType="hybrid" // standard | mutedStandard | hybrid | satellite
/>

Or specify a default one that should be shown on startup, while still allowing the user to cycle through them:

<AppleMaps
    defaultMapType="hybrid" // standard | mutedStandard | hybrid | satellite
/>

See:

Latitude and Longitude

Hi,

I'm giving the right latitude and longitude from Brasilia to <AppleMaps longitude={-47.93} latitude={-15.78} /> and <Annotation longitude={-47.93} latitude={-15.78} />, but the position on map are wrong:

image

I tried to change the props (latitude => longitude, vice-e-versa) and then it showed me the right result:

image

Looking in the source code, i found that you made a mistake (or maybe Apple changed) in the parameters of mapkit.Coordinate(longitude, latitude) (AppleMaps.js#L184). The right order is mapkit.Coordinate(latitude, longitude) Mapkit Docs.

Loading annotation from state

Hi guys,

There is a problem with kind of "dynamic annotation" I am trying to pass title of annotation to map but it's not rendering cause for component is undefined during loading process.

Production problem

When do the deploy into server, the map doesn't show the points, it's only in production using react.

I don't know why in localhost working but en host dont

Full globe mode

Just wondering is there away to show the full world instead of just Australia or a part of the map.

I am wanting to show all of our server locations/

Solutions if not available:
List on the right hand side that can be clicked on, and that can move the map.

Looking forward to your feedback.

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.