Modules.Map

Add-on Map module

Requirements

  • Google Maps API key (required for both development and production)
  • Google Play services SDK installed using the Android SDK manager
  • This module only works on Android devices. This module is not supported on the Android emulator

Getting Started

  • Edit the modules section of your tiapp.xml file to include this module:

    <ti:app>
        <modules>
            <!-- Add this line to your modules section -->
            <module platform="android">ti.map</module>
        </modules>
    </ti:app>
    
  • Obtain a Google Maps API key. For instructions, refer to the "Obtain and Add a Google API Key" section in the Google Maps v2 for Android guide.

  • Add the following meta-tag element to the Android manifest section of the tiapp.xml file. You may need to add the manifest and application elements.

    <ti:app>
        <android xmlns:android="http://schemas.android.com/apk/res/android">
            <manifest>
                <application>
                    <!-- Replace "YOUR_API_KEY" with the Google API key you obtained -->
                    <meta-data 
                        android:name="com.google.android.geo.API_KEY"
                        android:value="YOUR_API_KEY" />
                </application>
            </manifest>
        </android>
    </ti:app>
    
  • Instantiate the module with the require('ti.map') method, then make subsequent API calls with the new map object.

    var Map = require('ti.map');
    var mapview = Map.createView({ 
      mapType: Map.NORMAL_TYPE 
    });
    

iOS

This module is a replacement for the built-in Titanium.Map module on iOS.

For more instructions and examples of using the module, refer to the iOS Map Kit guide.

Requirements

  • Applications using this module must be built using Xcode 5 or later.

Getting Started

  • Edit the modules section of your tiapp.xml file to include this module:

    <ti:app>
        <modules>
            <!-- Add this line to your modules section -->
            <module platform="iphone">ti.map</module>
        </modules>
    </ti:app>
    
  • To use the userLocation property in iOS 8 and later, add either the NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription key to the iOS plist section of the project's tiapp.xml file.

    <ti:app>
        <ios>
            <plist>
                <dict>
                    <key>NSLocationAlwaysUsageDescription</key>
                    <string>
                        Specify the reason for accessing the user's location information.
                        This appears in the alert dialog when asking the user for permission to
                        access their location.
                    </string>
                </dict>
            </plist>
        </ios>
    </ti:app>
    
  • Instantiate the module with the require('ti.map') method, then make subsequent API calls with the new map object.

    var Map = require('ti.map');
    var mapview = Map.createView({
      mapType: Map.NORMAL_TYPE
    });
    

Breaking Changes

  • The addRoute method no longer accepts a dictionary as a parameter. Pass a Modules.Map.Route object instead.

Examples

Basic Map Example

This is a basic map example that places a custom annotation on the map, and listens for click events on the annotation.

In this example, a custom property (myid) is added to the annotation object. While adding custom members to a Titanium object is not generally recommended, in this case it provides a mechanism for uniquely identifying an annotation. This can be useful, for example, if the annotations are dynamically generated and it is not practical to identify them by title.

var Map = require('ti.map');
var win = Titanium.UI.createWindow();

var mountainView = Map.createAnnotation({
    latitude: 37.390749,
    longitude: -122.081651,
    title: 'Appcelerator Headquarters',
    subtitle: 'Mountain View, CA',
    pincolor: Map.ANNOTATION_RED,
    myid: 1 // Custom property to uniquely identify this annotation.
});

var mapview = Map.createView({
    mapType: Map.NORMAL_TYPE,
    region: { 
        latitude: 33.74511,
        longitude: -84.38993,
        latitudeDelta: 0.01,
        longitudeDelta: 0.01
    },
    animate: true,
    regionFit: true,
    userLocation: true,
    annotations: [ mountainView ]
});

var circle = Map.createCircle({
    center: {
        latitude: 33.74511,
        longitude: -84.38993
    },
    radius: 1000, // = 1.0 km
    fillColor: '#20FF0000'
});
mapview.addCircle(circle);

win.add(mapview);

mapview.addEventListener('click', function(event) {
    Ti.API.info('Clicked ' + event.clicksource + ' on ' + event.latitude + ', ' + event.longitude);
});
win.open();

Alloy XML Markup

Previous example as an Alloy view.

In XML markup, use the View element with the module attribute set to ti.map to create an instance of a map view, then use the Annotation element to define an annotation.

In the initializer file, load the map module and assign it to the Alloy.Globals.Map namespace. This variable can be used to reference map module constants in the project, as seen in the TSS file to assign the pincolor attribute.

alloy.js:

// Loads the map module to the global Alloy scope, which can be referenced by Alloy.Globals.Map
Alloy.Globals.Map = require('ti.map');

app/views/index.xml:

<Alloy>
    <Window>
        <Module id="mapview" module="ti.map" onClick="report" method="createView">
            <Annotation id="appcHQ" myId="1337" />
        </Module>
    </Window>
</Alloy>

app/styles/index.tss:

"#mapview": {
    region: {
        latitude: 33.74511,
        longitude: -84.38993,
        latitudeDelta: 0.01,
        longitudeDelta: 0.01
    }
},
"#appcHQ": {
    latitude: 37.368122,
    longitude: -121.913653,
    title: "Appcelerator Headquarters",
    subtitle: "San Jose, CA",
    pincolor: Alloy.Globals.Map.ANNOTATION_RED
}

app/controllers/index.js:

function report(event) {
    Ti.API.info('Annotation ' + event.title + ' clicked, ID: ' + event.annotation.myID);
}

$.index.open();

Map Clustering (iOS 11+)

This is a map-example which creates marker annotation and clustering of annotations.

The clusterIdentifier property and the clusterstart event are required in order to enable clustering. You can control the clustering by defining the collisionMode property and setting special cluster annotations using the setClusterAnnotation method on your map view instance.

var Map = require('ti.map');
var win = Titanium.UI.createWindow();
var annotations = [];

for (var i = 0; i < 10; i++) {
    annotations.push(Map.createAnnotation({
        title: 'Appcelerator Inc.',
        subtitle: 'TiRocks!',
        clusterIdentifier: 'abc', // Required for clusters
        collisionMode: Map.ANNOTATION_VIEW_COLLISION_MODE_RECTANGLE,
        showAsMarker: true,
        markerGlyphText: i.toString(),
        markerColor: 'blue',
        markerGlyphColor: 'green',
        markerTitleVisibility: Map.FEATURE_VISIBILITY_VISIBLE,
        markerSubtitleVisibility: Map.FEATURE_VISIBILITY_HIDDEN,
        markerGlyphImage: 'path/to/flag.png',
        markerSelectedGlyphImage: 'path/to/flag-selected.png',
        annotationDisplayPriority: Map.FEATURE_DISPLAY_PRIORITY_DEFAULT_LOW,
        latitude: (Math.random() * 10) + 40,
        longitude: Math.random() * 10,
    }));
}

var mapview = Map.createView({
    annotations: annotations,
    rotateEnabled: true,
    mapType: Map.MUTED_STANDARD_TYPE,
    showsPointsOfInterest: false,
    userLocation: true
});

mapview.addEventListener('clusterstart', function(e) {
    Ti.API.info('clustering started!');

    var clusterAnnotation = Map.createAnnotation({
        showAsMarker: true,
        markerText: e.memberAnnotations.length.toString(),
        title: 'Cluster Title',
        subtitle: 'Cluster Subtitle',
    });

    mapview.setClusterAnnotation({
        annotation: clusterAnnotation,
        memberAnnotations: e.memberAnnotations
    });
});
win.add(mapview);
win.open();
  • 3.1.0
  • 3.2.0
  • 3.2.0
Defined By

Properties

Modules.Map
: Numberreadonly
Color constant used to set a map annotation to azure via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to azure via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Color constant used to set a map annotation to blue via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to blue via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Color constant used to set a map annotation to cyan via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to cyan via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
ANNOTATION_DRAG_STATE_END : Numberreadonly

Used in the pinchangedragstate event to indicate that the user finished moving the annotation.

Used in the pinchangedragstate event to indicate that the user finished moving the annotation.

Modules.Map
ANNOTATION_DRAG_STATE_START : Numberreadonly

Used in the pinchangedragstate event to indicate that the user started dragging the annotation.

Used in the pinchangedragstate event to indicate that the user started dragging the annotation.

Modules.Map
ANNOTATION_GREEN : Numberreadonly

Color constant used to set a map annotation to green via the Modules.Map.Annotation.pincolor property.

Color constant used to set a map annotation to green via the Modules.Map.Annotation.pincolor property.

Modules.Map
: Numberreadonly
Color constant used to set a map annotation to magenta via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to magenta via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Color constant used to set a map annotation to orange via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to orange via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
ANNOTATION_PURPLE : Numberreadonly

Color constant used to set a map annotation to purple via the Modules.Map.Annotation.pincolor property.

Color constant used to set a map annotation to purple via the Modules.Map.Annotation.pincolor property.

  • 6.1.0
  • 3.2.0
  • 3.2.0
Modules.Map
ANNOTATION_RED : Numberreadonly

Color constant used to set a map annotation to red via the Modules.Map.Annotation.pincolor property.

Color constant used to set a map annotation to red via the Modules.Map.Annotation.pincolor property.

Modules.Map
: Numberreadonly
Color constant used to set a map annotation to rose via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to rose via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Constant indicating that a circle inscribed in the collision frame rectangle should be used to determine collisions. ...

Constant indicating that a circle inscribed in the collision frame rectangle should be used to determine collisions.

Requires: iOS 11.0 and later

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that the full collision frame rectangle should be used for detecting collisions. ...

Constant indicating that the full collision frame rectangle should be used for detecting collisions.

Requires: iOS 11.0 and later

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Color constant used to set a map annotation to violet via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to violet via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Color constant used to set a map annotation to yellow via the Modules.Map.Annotation.pincolor property. ...

Color constant used to set a map annotation to yellow via the Modules.Map.Annotation.pincolor property.

Requires: iOS 9.0 and later

  • 3.1.0
  • 6.1.0
  • 6.1.0
Modules.Map
: Numberreadonly
Constant indicating that the item's display priority is high. ...

Constant indicating that the item's display priority is high.

Requires: iOS 11.0 and later

An annotation view with this priority is removed from the map when its bounds collide with the bounds of another view with a higher priority. If the priorities of the two views are equal, the view furthest from the center of the map's visible region is hidden first.

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that the item's display priority is low. ...

Constant indicating that the item's display priority is low.

Requires: iOS 11.0 and later

An annotation view with this priority is removed from the map when its bounds collide with the bounds of another view with a higher priority. If the priorities of the two views are equal, the view furthest from the center of the map's visible region is hidden first.

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that the item is required. ...

Constant indicating that the item is required.

Requires: iOS 11.0 and later

An annotation view with this priority does not participate in clustering.

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that title text adapts to the current map state. ...

Constant indicating that title text adapts to the current map state.

Requires: iOS 11.0 and later

For markers in the normal state, title text is displayed and subtitle text is hidden. When a marker is selected, the title and subtitle text are hidden when the marker requires a callout.

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that title text is always hidden. ...

Constant indicating that title text is always hidden.

Requires: iOS 11.0 and later

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Constant indicating that title text is always visible. ...

Constant indicating that title text is always visible.

Requires: iOS 11.0 and later

  • 6.3.0
  • 6.3.0
Modules.Map
: Numberreadonly
Used with mapType to display a satellite flyover image of the area with road and road name information layered on top. ...

Used with mapType to display a satellite flyover image of the area with road and road name information layered on top. Available in iOS 9.0 and later.

  • 3.2.0
  • 3.2.0
Modules.Map
HYBRID_TYPE : Numberreadonly

Used with mapType to display a satellite image of the area with road and road name information layered on top.

Used with mapType to display a satellite image of the area with road and road name information layered on top.

Modules.Map
: Numberreadonly
Used with mapType to display a street map where your data is emphasized over the underlying map details. ...

Used with mapType to display a street map where your data is emphasized over the underlying map details. Available in iOS 11.0 and later. On Android it is mapped to NORMAL_TYPE.

Requires: iOS 11.0 and later

Modules.Map
NORMAL_TYPE : Numberreadonly

Used with mapType to display a street map that shows the position of all roads and some road names.

Used with mapType to display a street map that shows the position of all roads and some road names.

Modules.Map
: Numberreadonly
Place the overlay above roadways but below map labels, shields, or point-of-interest icons. ...

Place the overlay above roadways but below map labels, shields, or point-of-interest icons. Available in iOS 7.0 and later.

  • 3.2.0
  • 3.2.0
Modules.Map
: Numberreadonly
Place the overlay above map labels, shields, or point-of-interest icons but below annotations and 3D projections of b...

Place the overlay above map labels, shields, or point-of-interest icons but below annotations and 3D projections of buildings. Available in iOS 7.0 and later.

  • 3.2.0
  • 3.2.0
Modules.Map
POLYLINE_PATTERN_DASHED : Numberreadonly

Polyline type constant used to display a dashed polyline via Modules.Map.Polyline.pattern property.

Polyline type constant used to display a dashed polyline via Modules.Map.Polyline.pattern property.

  • 6.2.0
  • 6.2.0
  • 6.2.0
Modules.Map
POLYLINE_PATTERN_DOTTED : Numberreadonly

Polyline type constant used to display a dotted polyline via Modules.Map.Polyline.pattern property.

Polyline type constant used to display a dotted polyline via Modules.Map.Polyline.pattern property.

  • 6.2.0
  • 6.2.0
  • 6.2.0
Modules.Map
: Numberreadonly
Used in the regionwillchange event. ...

Used in the regionwillchange event. The animation was initiated in response to the user actions.

  • 3.1.0
Modules.Map
: Numberreadonly
Used in the regionwillchange event. ...

Used in the regionwillchange event. The camera moved in response to a request from the application.

  • 3.1.0
Modules.Map
: Numberreadonly
Used in the regionwillchange event. ...

Used in the regionwillchange event. The camera moved in response to the user gestures on the map.

  • 3.1.0
Modules.Map
: Numberreadonly
Used with mapType to display satellite flyover imagery of the area. ...

Used with mapType to display satellite flyover imagery of the area. Available in iOS 9.0 and later.

  • 3.2.0
  • 3.2.0
Modules.Map
SATELLITE_TYPE : Numberreadonly

Used with mapType to display satellite imagery of the area.

Used with mapType to display satellite imagery of the area.

Modules.Map
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services has been disabled on this device.

  • 3.1.0
Modules.Map
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. The version of Google Play services installed on this device is not authentic.

  • 3.1.0
Modules.Map
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is not installed on the device.

  • 3.1.0
Modules.Map
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is out of date.

  • 3.1.0
Modules.Map
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is available, and the connection is successful.

  • 3.1.0
Modules.Map
TERRAIN_TYPE : Numberreadonly

Used with mapType to display the terrain that shows the position of all roads and some road names.

Used with mapType to display the terrain that shows the position of all roads and some road names.

  • 3.1.0
apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Defined By

Methods

Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Modules.Map
( [parameters] ) : Modules.Map.Annotation
Creates and returns an instance of Modules.Map.Annotation. ...

Creates and returns an instance of Modules.Map.Annotation.

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Camera
Creates and returns an instance of Modules.Map.Camera. ...

Creates and returns an instance of Modules.Map.Camera.

  • 3.2.0
  • 3.2.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Circle
Creates and returns an instance of Modules.Map.Circle. ...

Creates and returns an instance of Modules.Map.Circle.

  • 4.1.0
  • 4.1.0
  • 4.1.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.ImageOverlay
Creates and returns an instance of Modules.Map.ImageOverlay. ...

Creates and returns an instance of Modules.Map.ImageOverlay.

  • 7.4.0
  • 7.2.0
  • 7.2.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Polygon
Creates and returns an instance of Modules.Map.Polygon. ...

Creates and returns an instance of Modules.Map.Polygon.

  • 4.1.0
  • 4.1.0
  • 4.1.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Polyline
Creates and returns an instance of Modules.Map.Polyline. ...

Creates and returns an instance of Modules.Map.Polyline.

  • 4.1.0
  • 4.1.0
  • 4.1.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Route
Creates and returns an instance of Modules.Map.Route. ...

Creates and returns an instance of Modules.Map.Route.

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.Snapshotter
Creates and returns an instance of Modules.Map.Snapshotter. ...

Creates and returns an instance of Modules.Map.Snapshotter.

  • 6.0.0
  • 6.0.0

Parameters

Returns

Creates and returns an instance of Modules.Map.StreetViewPanorama. ...

Creates and returns an instance of Modules.Map.StreetViewPanorama.

  • 5.2.0

Parameters

Returns

Modules.Map
( [parameters] ) : Modules.Map.View
Creates and returns an instance of Modules.Map.View. ...

Creates and returns an instance of Modules.Map.View.

Parameters

Returns

Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Modules.Map
( ) : Number
Returns a code to indicate whether Google Play Services is available on the device. ...

Returns a code to indicate whether Google Play Services is available on the device.

  • 3.1.1

Returns

Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void