Titanium: 如何在地图上显示多个注解?[英] Titanium: How to show multiple Annotations on Map?

本文是小编为大家收集整理的关于Titanium: 如何在地图上显示多个注解?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

它在钛SDK上的第2天.

我想在地图上显示多个注释.我已经引用了答案,但找不到修复!

我尝试了以下代码: -

// 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 ;
}

但我收到这个错误

[错误]无效类型传递给函数.预计:nsdictionary,是: __nsarraym In - [TimapView AnnotationFromarg:](TimaPview.m:96)

任何建议?

谢谢...

推荐答案

解决了!!!

刚替换了这一代码:

 annotations:[createAnnotations()],

 annotations:createAnnotations(),

本文地址:https://www.itbaoku.cn/post/1938210.html

问题描述

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...

推荐答案

Solved !!!

Just replaced this line of code :

 annotations:[createAnnotations()],

with

 annotations:createAnnotations(),