我试图在Titanium中为我的地图添加注释,并且我一直都会遇到这个错误:
" line = 37;
message ="传递给函数的无效类型&#34 ;;
传递给函数"
的类型无效nativeLocation =" - [TiMapViewProxy annotationFromArg:](TiMapViewProxy.m:120)&#34 ;;
nativeReason ="期望:对象,是:NSNull&#34 ;;"
这是我的代码。据我所知它应该有用。
//This is the code to implement a map and store locations using annotations
var locationsTabGroup = Titanium.UI.createTabGroup({
barColor: '#E62B2B'
});
var locationsToHome = Titanium.UI.createButton({
title: 'Back',
titleAttributes: {
color: 'white'
},
backgroundImage: 'images/revisedbackbutton2.png',
height: 35,
width: 80,
borderRadius: 10
});
var locationsWindow = Titanium.UI.createWindow({
leftNavButton: locationsToHome,
title:'Select Store',
tabBarHidden: true,
titleAttributes: {
color:'white'
}
});
var MapModule = require('ti.map');
var locationsMap = MapModule.createView({
mapType: MapModule.NORMAL_TYPE,
animate: true,
region: {latitude: -27.962939, longitude: 153.382428, latitudeDelta: 0.1, longitudeDelta: 0.1 },
height: '100%',
top: 0,
width: Ti.UI.FILL,
annotations: [store1]
});
var store1 = MapModule.createAnnotation({
latitude: -27.465868,
longitude: 153.028309,
pincolor: MapModule.ANNOTATION_RED,
title: 'Pita Pit Brisbane',
subtitle: '280 Adelaide St, Brisbane QLD 4000'
});
var store2 = MapModule.createAnnotation({
latitude: -27.499154,
longitude: 152.972711,
pincolor: MapModule.ANNOTATION_RED,
title: 'Pita Pit Indooroopilly',
subtitle: '322 Moggill Rd, Indooroopilly QLD 4068'
});
var store3 = MapModule.createAnnotation({
latitude: -27.453312,
longitude: 153.034908,
pincolor: MapModule.ANNOTATION_RED,
title: 'Pita Pit Green Square',
subtitle: '6/515 St Pauls Terrace, Fortitude Valley QLD 4006'
});
var locationsTab = Titanium.UI.createTab({
window: locationsWindow
});
locationsWindow.add(locationsMap);
locationsTabGroup.addTab(locationsTab);
答案 0 :(得分:0)
您正在使用注释创建之前。 在将它们传递给地图之前,您应该声明所有注释。
或者,不要在创建时设置注释,并在声明注释后使用locationsMap.setAnnotations([store1, store2, store3]);
。