0.0.3 • Published 6 years ago

ion-maps v0.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

IonMaps

It's a simple set of components to help ease the development process when using google maps with Ionic.

Dependencies

In order to run this project properly, you have to install the native maps plugin as such:

$ ionic cordova plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YourApiKeyHere" --variable API_KEY_FOR_IOS="YourKeyApiHere" --variable LOCATION_WHEN_IN_USE_DESCRIPTION="Show your location on the map" --variable LOCATION_ALWAYS_USAGE_DESCRIPTION="Trace your location on the map"
$ npm install --save @ionic-native/google-maps

If you run into any issues such as not finding google definition, run:

npm install --save @types/googlemaps

Components

Ion Maps

It's a component that renders the best possible google map on the device, depending on what platforms it's running on. If on web, it will use javascript google maps, if on a native device, it will use native google maps.

PropertyTypeDefinition
latstringLatitude position of the map. Required
lngstringLongitude position of the map. Required
heightstringHeight of the element. Can be used in %, px, em, rem. Defaults to '100%'
widthstringWidth of the element. Can be used in %, px, em, rem. Defaults to '100%'
zoomnumberInitial zoom of the map. Defaults to 15
tiltnumberInitial tilt of the map.
mapStylestring or jsonTheme of the map. Possible values: standard, silver, light, dark, night, midnight, aubergine, military, paledawn, red, purple, green, yellow. You can also pass a custom style json object with your own custom properties. Defaults to standard.
showGeolocationbooleanWhether or not to show a pulsating dot in your geolocation. Defaults to false.

Usage ps: The component can be used with or without markers.

<ion-content>
  <ion-maps mapStyle="military" lat="40.714728" lng="-73.998672">
    <!--Normal marker-->
    <ion-marker lat="40.718417" lng="-73.996734" label="Y" title="Normal Marker"></ion-marker>

    <!--Custom icon marker-->
    <ion-marker lat="40.718217" lng="-73.991434" title="Custom icon" iconUrl="http://icons.iconarchive.com/icons/paomedia/small-n-flat/48/map-marker-icon.png"></ion-marker>

    <!--Custom HTML marker-->
    <ion-marker lat="40.717317" lng="-73.995284" parentClass="custom-marker-outer" customHTML="<div class='custom-marker-inner'></div>"></ion-marker>
  </ion-maps>

  <!-- Or without markers -->
  <ion-maps lat="40.714728" lng="-73.998672"></ion-maps>
  
<ion-content>

Ion Static Maps

Renders a static for moments where you need a fast rendered page that doesn't need map interaction.

PropertyTypeDefinition
latstringLatitude position of the map. Required if not using address.
lngstringLongitude position of the map. Required if not using address.
addressstringAddress position of the map. Can be a search string such as New York Street, 129. Ignored if lat lng is also passed.
heightnumberHeight of the element in px. Defaults to 400px
widthnumberWidth of the element. Defaults to 400px
zoomnumberInitial zoom of the map. Defaults to 15
formatstringImage format of the generated map. Possible values: png, jpeg, gif. Defaults to png.
languagestringLanguage of the map labels. Only works in certain countries.
mapTypestringType of the map. Possible values: HYBRID, ROADMAP, SATELLITE and TERRAIN.
mapStylestring or jsonTheme of the map. Possible values: standard, silver, light, dark, night, midnight, aubergine, military, paledawn, red, purple, green, yellow. You can also pass a custom style json object with your own custom properties. Defaults to standard.

Usage ps: The component can be used with or without markers.

<ion-content>
  <ion-static-maps mapStyle="silver" lat="40.714728" lng="-73.998672">
     <!--Normal marker-->
    <ion-marker lat="40.718417" lng="-73.996734" color="yellow" label="Y"></ion-marker>

    <!--Custom icon marker-->
    <ion-marker lat="40.718217" lng="-73.991434" iconUrl="http://icons.iconarchive.com/icons/paomedia/small-n-flat/48/map-marker-icon.png"></ion-marker>
  </ion-static-maps>

  <!-- Or without markers -->
  <ion-static-maps lat="40.714728" lng="-73.998672"></ion-static-maps>
</ion-content>

Ion Marker

Note that this component can be used with both <ion-maps> and <ion-static-maps>.

PropertyTypeDefinition
latstringLatitude position of the marker. Required if not using address.
lngstringLongitude position of the marker. Required if not using address.
addressstringAddress position of the marker. Can be a search string such as New York Street, 129. Ignored if lat lng is also passed.
titlestringTitle of the marker. Only works on ion-maps
labelstringLabel of the marker. Single letter that appears on the pin. Ignored if using iconUrl.
iconUrlstringUrl for an icon that will be displayed as a pin. Works with small sized png and ico files.
colorstringColor of the pin. Only works on ion-static-maps. Possible values: yellow, red, green, blue, purple, orange, green or any hex color in 0xRRGGBB format.
draggablebooleanIf true, the marker will have a DROP animation on the screen. Default value is false.
animatedbooleanIf true, the marker dropped with an animation to the map. Default value is false.
visiblebooleanIf true, the marker visible in the map. Default value is false.
opacitynumberMarker's opacity between 0.0 and 1.0. Only works with javascript maps. Defaults to 1.
zIndexnumberzIndex of the marker. Defaults to 1.
customHTMLstringHTML to compose a custom marker element. Only works on javascript maps.
parentClassstringClass or classes to be added on the parent div of a customHTML marker element. Use it along with customHTML, but not required.

Styling

As stated above, both ion-maps and ion-static-maps accept a property named mapStyle. It takes either a string with a name of a predefined style, or a custom style object, of which you can get on Maps Style Wizard or Snazzy Maps.

If you don't use this param, the map will be rendered with default styles. In case you choose to use one of the presets, this is what the map is going to look like: