Titanium: How to show multiple Annotations on Map?

时间秒杀一切 提交于 2019-12-13 05:48:58

问题


Its mine 2nd day on Titanium SDK.

I want to show multiple annotations on the map. I have referred answers at SO but couldn't find fix !

I tried below code : -

// To create map
var mapview = Titanium.Map.createView({
        mapType: Titanium.Map.STANDARD_TYPE,
        region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
        animate:true,
        regionFit:true,
        userLocation:true,
        annotations:[createAnnotations()],
        top:110,
        height:200
    });  

// CREATE ANNOTATIONS

function createAnnotations ()
{
    var annoatationData = [];
    for (var i=0; i < 10; i++) 
    {
            var mountainView = Titanium.Map.createAnnotation(
            {
                latitude:37.390749,
                longitude:-122.081651,
                title:"Appcelerator Headquarters",
                subtitle:'Mountain View, CA',
                pincolor: isAndroid ? "orange" : Titanium.Map.ANNOTATION_RED,
                animate:true,
                myid:i // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS
            });

      annoatationData.push(mountainView);
    };  

    return annoatationData ;
}

But I am getting this error

[ERROR] Invalid type passed to function. expected: NSDictionary, was: __NSArrayM in -[TiMapView annotationFromArg:] (TiMapView.m:96)

Any suggestions ?

Thanks...


回答1:


Solved !!!

Just replaced this line of code :

 annotations:[createAnnotations()],

with

 annotations:createAnnotations(),


来源:https://stackoverflow.com/questions/9128566/titanium-how-to-show-multiple-annotations-on-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!