addMapPins。
嗚呼、目がしょぼしょぼする...。
「PhoneGapでMapKitを使って地図アプリを開発」を見ながら、ちょっとPhoneGapいじってたら
MapKitPlug.js での addMapPins の使い方で少しだけハマったのでメモ。
・間違った書き方
var marker = {
lat:35.3628410163896,
lon:138.73156428337097,
title:"富士山",
subTitle:"サブタイトル",
pinColor:"green",
imageURL : "",
index:0,
selected:true
};
window.plugins.mapKit.addMapPins(marker);
こうやって呼び出すと、以下のような文言でエラーになります。
[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance xxx
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '
-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance xxx'
何故かと言うと、
marker は MapKit の addMapPins:arguments:options の
arguments として渡される訳で、配列である事を期待されているから。
一方、MapKitPlug.js の addMapPins を見ると...
MapKitPlug.prototype.addMapPins = function(pins) {
var pinStr = "[]";
if(pins) pinStr = JSON.stringify(pins);
PhoneGap.exec("MapKitView.addMapPins", pinStr);
}
渡された pins は、そのまま JSON.stringify でシリアライズされて
MapKit に渡される訳だから、
pins が既に配列でなきゃアカンのでありまして。
そんなこったで、正解はこうらしいです...
var marker = {
lat:35.3628410163896,
lon:138.73156428337097,
title:"富士山",
subTitle:"サブタイトル",
pinColor:"green",
imageURL : "",
index:0,
selected:true
};
window.plugins.mapKit.addMapPins([marker]);