Home

Awesome

Cordova GoogleMaps plugin for Android, iOS and Browser v2.7.1

DownloadBuild test (multiple_maps branch)

This plugin displays Google Maps in your application. This plugin uses these libraries for each platforms:

Both PhoneGap and Apache Cordova are supported.

<table> <tr> <td> <h3>Android, iOS</h3> <img src="https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps-doc/master/v2.6.0/hello-world/image1.gif" height="300"> </td> <td> <h3>Browser</h3> <img src="https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/browser_demo.gif" height="300"> </td> </tr> </table>

Guides

Quick install

$> cordova plugin add cordova-plugin-googlemaps

Then set your Google Maps API keys into your config.xml (Android / iOS).

<widget ...>
  <preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="(api key)" />
  <preference name="GOOGLE_MAPS_IOS_API_KEY" value="(api key)" />
</widget>

For browser platform,

// If your app runs this program on browser,
// you need to set `API_KEY_FOR_BROWSER_RELEASE` and `API_KEY_FOR_BROWSER_DEBUG`
// before `plugin.google.maps.Map.getMap()`
//
//   API_KEY_FOR_BROWSER_RELEASE for `https:` protocol
//   API_KEY_FOR_BROWSER_DEBUG for `http:` protocol
//
plugin.google.maps.environment.setEnv({
  'API_KEY_FOR_BROWSER_RELEASE': '(YOUR_API_KEY_IS_HERE)',
  'API_KEY_FOR_BROWSER_DEBUG': ''  // optional
});

// Create a Google Maps native view under the map_canvas div.
var map = plugin.google.maps.Map.getMap(div);

PhoneGap Build settings

<widget ...>

  <!--
    You need to specify cli-7.1.0 or greater version.
    https://build.phonegap.com/current-support
  -->
  <preference name="phonegap-version" value="cli-8.1.1" />
</widget>

Install optional variables (config.xml)


Please support this plugin activity.

In order to keep this plugin as free, please consider to donate little amount for this project.

Donate


Release Notes


Demos

Demo (Browser)


Documentation

All documentations are here!!

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/README.md

Quick examples

<table> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Map/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/raw/master/images/map.png?raw=true"><br>Map</a></td> <td><pre> var options = { camera: { target: {lat: ..., lng: ...}, zoom: 19 } }; var map = plugin.google.maps.Map.getMap(mapDiv, options)</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Marker/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/marker.png?raw=true"><br>Marker</a></td> <td><pre> var marker = map.addMarker({ position: {lat: ..., lng: ...}, title: "Hello Cordova Google Maps for iOS and Android", snippet: "This plugin is awesome!" })</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/MarkerCluster/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/markercluster.png?raw=true"><br>MarkerCluster</a></td> <td><pre> var markerCluster = map.addMarkerCluster({ //maxZoomLevel: 5, boundsDraw: true, markers: dummyData(), icons: [ {min: 2, max: 100, url: "./img/blue.png", anchor: {x: 16, y: 16}}, {min: 100, max: 1000, url: "./img/yellow.png", anchor: {x: 16, y: 16}}, {min: 1000, max: 2000, url: "./img/purple.png", anchor: {x: 24, y: 24}}, {min: 2000, url: "./img/red.png",anchor: {x: 32,y: 32}} ] });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/HtmlInfoWindow/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/htmlInfoWindow.png?raw=true"><br>HtmlInfoWindow</a></td> <td><pre> var html = "&lt;img src='./House-icon.png' width='64' height='64' &gt;" + "&lt;br&gt;" + "This is an example"; htmlInfoWindow.setContent(html); htmlInfoWindow.open(marker); </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Circle/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/circle.png?raw=true"><br>Circle</a></td> <td><pre> var circle = map.addCircle({ 'center': {lat: ..., lng: ...}, 'radius': 300, 'strokeColor' : '#AA00FF', 'strokeWidth': 5, 'fillColor' : '#880000' });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Polyline/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/polyline.png?raw=true"><br>Polyline</a></td> <td><pre> var polyline = map.addPolyline({ points: AIR_PORTS, 'color' : '#AA00FF', 'width': 10, 'geodesic': true });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Polygon/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/polygon.png?raw=true"><br>Polygon</a></td> <td><pre> var polygon = map.addPolygon({ 'points': GORYOKAKU_POINTS, 'strokeColor' : '#AA00FF', 'strokeWidth': 5, 'fillColor' : '#880000' });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/GroundOverlay/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/groundoverlay.png?raw=true"><br>GroundOverlay</a></td> <td><pre> var groundOverlay = map.addGroundOverlay({ 'url': "./newark_nj_1922.jpg", 'bounds': [ {"lat": 40.712216, "lng": -74.22655}, {"lat": 40.773941, "lng": -74.12544} ], 'opacity': 0.5 }); </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/TileOverlay/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/tileoverlay.png?raw=true"><br>TileOverlay</a></td> <td><pre> var tileOverlay = map.addTileOverlay({ debug: true, opacity: 0.75, getTile: function(x, y, zoom) { return "../images/map-for-free/" + zoom + "_" + x + "-" + y + ".gif" } });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/KmlOverlay/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/multiple_maps/images/kmloverlay.png?raw=true"><br>KmlOverlay</a></td> <td><pre> map.addKmlOverlay({ 'url': 'polygon.kml' }, function(kmlOverlay) { ... });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/Geocoder/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/geocoder.png?raw=true"><br>Geocoder</a></td> <td><pre> plugin.google.maps.Geocoder.geocode({ // US Capital cities "address": [ "Montgomery, AL, USA", ... "Cheyenne, Wyoming, USA" ] }, function(mvcArray) { ... });</pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/utilities/geometry/poly/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/poly.png?raw=true"><br>poly utility</a></td> <td><pre> var GORYOKAKU_POINTS = [ {lat: 41.79883, lng: 140.75675}, ... {lat: 41.79883, lng: 140.75673} ] var contain = plugin.google.maps.geometry.poly.containsLocation( position, GORYOKAKU_POINTS); marker.setIcon(contain ? "blue" : "red"); </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.6.0/class/utilities/geometry/encoding/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/encode.png?raw=true"><br>encode utility</a></td> <td><pre> var GORYOKAKU_POINTS = [ {lat: 41.79883, lng: 140.75675}, ... {lat: 41.79883, lng: 140.75673} ] var encodedPath = plugin.google.maps.geometry. encoding.encodePath(GORYOKAKU_POINTS); </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/utilities/geometry/spherical/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/spherical.png?raw=true"><br>spherical utility</a></td> <td><pre> var heading = plugin.google.maps.geometry.spherical.computeHeading( markerA.getPosition(), markerB.getPosition()); label.innerText = "heading : " + heading.toFixed(0) + "&deg;"; </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/locationservice/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/images/locationService.png?raw=true"><br>Location service</a></td> <td><pre> plugin.google.maps.LocationService.getMyLocation(function(result) { alert(["Your current location:\n", "latitude:" + location.latLng.lat.toFixed(3), "longitude:" + location.latLng.lng.toFixed(3), "speed:" + location.speed, "time:" + location.time, "bearing:" + location.bearing].join("\n")); }); </pre></td> </tr> <tr> <td><a href="https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/class/StreetView/README.md"><img src="https://github.com/mapsplugin/cordova-plugin-googlemaps/raw/master/images/streetview.png?raw=true"><br>StreetView</a></td> <td><pre> var div = document.getElementById("pano_canvas1"); var panorama = plugin.google.maps.StreetView.getPanorama(div, { camera: { target: {lat: 42.345573, lng: -71.098326} } });</pre></td> </tr> </table>

What is the difference between this plugin and Google Maps JavaScript API v3?

Google Maps JavaScript API v3 works on any platforms, but it does not work if device is offline.

This plugin uses three different APIs:

In Android and iOS applications, this plugin displays native Google Maps views, which is faster than Google Maps JavaScript API v3. And it even works if the device is offline.

In Browser platform, this plugin displays JS map views (Google Maps JavaScript API v3). It should work as PWA (progressive web application), but the device has to be online.

In order to work for all platforms, this plugin provides own API instead of each original APIs. You can write your code similar to the Google Maps JavaScript API v3.

Feature comparison table

Google Maps JavaScript API v3Cordova-Plugin-GoogleMaps(Android,iOS)Cordova-Plugin-GoogleMaps(Browser)
Rendering systemJavaScript + HTMLJavaScript + Native API'sJavaScript
Offline mapNot possiblePossible (only your displayed area)Not possible
3D ViewNot possiblePossibleNot possible
PlatformAll browsersAndroid and iOS applications onlyAll browsers
Tile imageBitmapVectorBitmap

Class comparison table

Google Maps JavaScript API v3Cordova-Plugin-GoogleMaps
google.maps.MapMap
google.maps.MarkerMarker
google.maps.InfoWindowDefault InfoWindow, and HtmlInfoWindow
google.maps.CircleCircle
google.maps.RectanglePolygon
google.maps.PolylinePolyline
google.maps.PolygonPolygon
google.maps.GroundOverlayGroundOverlay
google.maps.ImageMapTypeTileOverlay
google.maps.MVCObjectBaseClass
google.maps.MVCArrayBaseArrayClass
google.maps.Geocoderplugin.google.maps.geocoder
google.maps.geometry.sphericalplugin.google.maps.geometry.spherical
google.maps.geometry.encodingplugin.google.maps.geometry.encoding
google.maps.geometry.polyplugin.google.maps.geometry.poly
(not available)MarkerCluster
google.maps.KmlLayerKmlOverlay
(not available)LocationService
google.maps.StreetViewStreetView :sparkles:
google.maps.Data(not available)
google.maps.DirectionsService(not available)
google.maps.DistanceMatrixService(not available)
google.maps.TransitLayer(not available)
google.maps.places.*(not available)
google.maps.visualization.*(not available)

How does this plugin work (Android, iOS)?

This plugin generates native map views, and puts them under the browser.

The map views are not HTML elements. This means that they are not a <div> or anything HTML related. But you can specify the size and position of the map view using its containing <div>.

This plugin changes the background to transparent in your application. Then the plugin detects your touch position, which is either meant for the native map or an html element (which can be on top of your map, or anywhere else on the screen).

The benefit of this plugin is the ability to automatically detect which HTML elements are over the map or not.

For instance, in the image below, say you tap on the header div (which is over the map view). The plugin will detect whether your tap is for the header div or for the map view and then pass the touch event appropriately.

This means you can use the native Google Maps views similar to HTML elements.


Official Communities