The top level Map module. The Map module is used for creating in-application native maps.
deprecated
3.2.0 For new iOS and Android applications use the ti.map add-on module.
Support for the Titanium.Map
module in iOS and Android was removed in Release 3.2.0.
For all other platforms, continue to use this module.
This module provides native map support using Google Maps API v1. As of March 3, 2013, Google is no longer issuing Google Maps API v1 keys and this module can no longer be used to support native maps on Android unless you have these keys.
For new Android applications, use the ti.map add-on module to add native maps support for your application. If you have an application that still uses the old keys, you can either transition to the new module or continue using the built-in Titanium.Maps module.
Since Release 3.2.0, support for this module was removed. Use the ti.map add-on module.
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 win = Titanium.UI.createWindow();
var mountainView = Titanium.Map.createAnnotation({
latitude:37.390749,
longitude:-122.081651,
title:"Appcelerator Headquarters",
subtitle:'Mountain View, CA',
pincolor:Titanium.Map.ANNOTATION_RED,
animate:true,
leftButton: '../images/appcelerator_small.png',
myid:1 // Custom property to uniquely identify this annotation.
});
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: {latitude:37.390749, longitude:-122.081651,
latitudeDelta:0.01, longitudeDelta:0.01},
animate:true,
regionFit:true,
userLocation:true,
annotations:[mountainView]
});
win.add(mapview);
// Handle click events on any annotations on this map.
mapview.addEventListener('click', function(evt) {
Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
// Check for all of the possible names that clicksouce
// can report for the left button/view.
if (evt.clicksource == 'leftButton' || evt.clicksource == 'leftPane' ||
evt.clicksource == 'leftView') {
Ti.API.info("Annotation " + evt.title + ", left button clicked.");
}
});
win.open();
// For the iOS platform, wait for the complete event to ensure the region is set
if (Ti.Platform.name == 'iPhone OS') {
mapview.addEventListener('complete', function(evt){
mapview.region = {
latitude:37.390749, longitude:-122.081651,
latitudeDelta:0.01, longitudeDelta:0.01
};
});
}
Previous example as an Alloy view.
index.xml:
<Alloy>
<Window id="win">
<!-- Note the ns attribute is used to change the default namespace. -->
<View id="mapview" ns="Ti.Map" onClick="doClick" onComplete="setRegion"
animate="true" regionFit="true" userLocation="true"
mapType="Ti.Map.STANDARD_TYPE" >
<Annotation id="mountainView"
latitude="37.390749" longitude="-122.081651"
title="Appcelerator Headquarters" subtitle="Mountain View, CA"
pincolor="Titanium.Map.ANNOTATION_RED"
leftButton="/images/appcelerator_small.png"
myid="1"/>
<!-- Place other child views here, such as an ImageView to add an overlay. -->
</View>
</Window>
</Alloy>
index.js:
function doClick(evt){
Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
// Check for all of the possible names that clicksouce
// can report for the left button/view.
if (evt.clicksource == 'leftButton' || evt.clicksource == 'leftPane' ||
evt.clicksource == 'leftView') {
Ti.API.info("Annotation " + evt.title + ", left button clicked.");
}
};
function setRegion(evt) {
// For the iOS platform, wait for the complete event to ensure the region is set
if (OS_IOS) {
$.mapview.region = {
latitude:37.390749, longitude:-122.081651,
latitudeDelta:0.01, longitudeDelta:0.01
};
}
}
// These parameters can also be defined in the TSS file.
$.mapview.annotations = [$.mountainView];
$.mapview.region = {latitude:37.390749, longitude:-122.081651, latitudeDelta:0.01, longitudeDelta:0.01};
$.win.open
Used in the pinchangedragstate event to indicate that the user canceled the drag action.
Used in the pinchangedragstate event to indicate that the user canceled the drag action.
Used in the pinchangedragstate event to indicate that the user moved the annotation.
Used in the pinchangedragstate event to indicate that the user moved the annotation.
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.
Used in the pinchangedragstate event to indicate that the annotation is not being dragged.
Used in the pinchangedragstate event to indicate that the annotation is not being dragged.
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.
Color constant used to set a map annotation to green via the Titanium.Map.Annotation.pincolor property.
Color constant used to set a map annotation to green via the Titanium.Map.Annotation.pincolor property.
Color constant used to set a map annotation to purple via the Titanium.Map.Annotation.pincolor property.
Color constant used to set a map annotation to purple via the Titanium.Map.Annotation.pincolor property.
Color constant used to set a map annotation to red via the Titanium.Map.Annotation.pincolor property.
Color constant used to set a map annotation to red via the Titanium.Map.Annotation.pincolor property.
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.
On Android, HYBRID_TYPE
produces a road map that looks like
STANDARD_TYPE, and does not include a satellite
image. This is a known issue
(TIMOB-9673).
Use SATELLITE_TYPE to specify a hybrid-type map on Android.
Used with mapType to display satellite imagery of the area.
Used with mapType to display satellite imagery of the area.
The Android Google Maps API does not support displaying satellite imagery
without roads and names, so specifying SATELLITE_TYPE
on Android produces
the same results as HYBRID_TYPE on other platforms.
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
.
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.
Default: true
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.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
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.
A dictionary of properties to apply.
Creates and returns an instance of Titanium.Map.Annotation.
deprecated
3.2.0 For new Android applications or to use Google Maps v2, use the ti.map add-on module.
For the iOS platform, use the ti.map add-on module. Support for the
Titanium.Map
module on iOS was removed in Release 3.2.0.
For all other platforms, continue to use this module.
Properties to set on a new object, including any defined by Titanium.Map.Annotation except those marked not-creation or read-only.
Creates and returns an instance of Titanium.Map.View.
deprecated
3.2.0 For new iOS and Android applications use the ti.map add-on module.
Support for the Titanium.Map
module in iOS and Android was removed in Release 3.2.0.
For all other platforms, continue to use this module.
Properties to set on a new object, including any defined by Titanium.Map.View except those marked not-creation or read-only.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback
parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.