imhotep / MapKit

Cordova MapKit plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

need some help getting setup

samburgers opened this issue · comments

Hi, am still trying to get this working on iOS. When installing with plugman i was just returning "error". So i tried using the 3.0 CLI as suggested in a different thread, which seems to install the MapKit plugin ok, but i cant execute any of the MapKit js code from the app. Here are my steps exactly from step dot. please can you let me know what i am doing wrong.

  • install cordova:
    npm install -g cordova
  • create new cordova project:
    phonegap create hello com.example.hello HelloWorld
  • go into app folder:
    cd hello
  • add and build iOS version
    phonegap build ios
  • add any core plugins i need (ie console logger):
    phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
  • add MapKit plugin:
    phonegap local plugin add https://github.com/imhotep/MapKit.git
  • edit www/js/index.js
  • rebuild
    phonegap build ios
  • open project in xcode, and compile app to device...

so, the app launches but don't see the map. even when i remove the sample code and just try and console.log(MapKit); i get nothing returned.

it doesnt look like the MapKit.js code is getting compiled into cordova_plugins.js on build. is it meant to, or should i reference the MapKit.js file in my html? i see that upon build it creates the file platforms/ios/www/js/MapKit.js, but when i just try to reference that in the html, the logger in xcode gives me this

2013-09-13 22:28:54.190 HelloWorld[6416:c07] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0xaa699b0
2013-09-13 22:28:54.191 HelloWorld[6416:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0xaa699b0'
*** First throw call stack:
(0x103012 0x2978e7e 0x18e4bd 0xf2bbc 0xf294e 0x3b05b 0x196c3 0x18efb 0x18a6d 0x18bf6 0x18b23 0x298c6b0 0x149e765 0x86f3f 0x8696f 0xa9734 0xa8f44 0xa8e1b 0x37a97e3 0x37a9668 0x33effc 0x1f72c 0x1f68d 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

is there perhaps anything i need to put into the global config.xml to make it work?

thanks so much for your help :)

@samburgers

The best way is to download the phonegap distribution. phonegap and cordova cli just add complications and chances of errors. Once you have downloaded phonegap distribution. You need to follow these steps:

$ cd /path/to/cordova-ios
$ ./bin/create ~/Projects/ios-example com.mypackage iOS-example
$ plugman install --platform ios --project ~/Projects/ios-example --plugin /path/to/MapKit
# if you want to test out the plugin you can copy the sample provided with the plugin. Make sure you've got the iOS version of cordova.js copied as well.
$ cp -r /path/to/MapKit/sample/* ~/Projects/ios-example/

You then open Xcode and try to build&run (or you can use ./cordova/build and ./cordova/run)

@imhotep thanks for the reply, that is much clearer. Is there plans in the future to support the phonegap CLI? maybe im doing something wrong, but does the workflow you outlined now mean i need to keep separate codebases for iOS and Android versions? the most appealing thing about the phonegap CLI for me is that i can keep it all in one place. thanks again

@imhotep sorry to pester, but just wondering if phonegap CLI support is on the roadmap? am happy to change my project workflow to the one you outlined, but would also hold out for CLI support if thats on the cards. cheers :)

@samburgers

I am sorry, I've been busy with other issues. The thing is that phonegap-cli is not actively being maintained right now. It is barely trying to catch up with cordova-cli. I will make sure that the plugin works with cordova-cli though.

I will update this issue once I've verified.

-a

@samburgers

So the issue with adding support for cordova or phonegap cli is that neither of them support variables which means mapkit would not properly work on Android. You can still add the plugin with the following command:

cordova plugin add com.phonegap.plugins.mapkit

But you would need to update your platforms/android folder in order to get it to work on Android (with the additional permissions and API KEY). It could be a temporary solution for you.

@imhotep thanks heaps for the replies. yep, i would be happy to just update the android folder manually in exchange for keeping the workflow of the native CLI, as it seems everything is moving in that direction, and the single app codebase suits me greatly.

so, i just upgraded to Cordova 3.1 with the CLI, and then tried to instal mapkit via the plugin registry method above. it seems to install fine, and compiles to iOS fine, but mapkit code doesnt seem to be working. is there perhaps meant to be a reference to the js in cordova_plugins.js, or anything else i am missing? thanks again :)

nope there shouldn't be any references to cordova_plugins.js

I will give it a try for iOS and report back shortly

cool thanks @imhotep, so when adding 'native' plugins via the cordova CLI, the installer will add a reference to the plugin js in platforms/ios/www/cordova_plugins.js

this is the created file for 'logger' plugin:

cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
    {
        "file": "plugins/org.apache.cordova.console/www/console-via-logger.js",
        "id": "org.apache.cordova.console.console",
        "clobbers": [
            "console"
        ]
    },
    {
        "file": "plugins/org.apache.cordova.console/www/logger.js",
        "id": "org.apache.cordova.console.logger",
        "clobbers": [
            "cordova.logger"
        ]
    }
]
});

is this supposed to be different for the MapKit plugin?

thanks!

@samburgers

If I am not mistaken cordova_plugins.js contains plugins that need to be there at load time. MapKit does not need to be there at load time and can be loaded on-demand. So it doesn't have to be in that file as far as I know.
cordova_plugins.js is meant to replace the old monolithic {phonegap,cordova}.js and is part of cordova 3.0's plugin architecture change.

When you say 'it doesn't seem to be working' what do you exactly mean? Do you get an error ? Does the map just now show up ? A good way to debug is to launch Xcode inside your platforms/ios project OR to run ./cordova/log inside your platforms/ios project and see what happens when you try to load the map.

ok cool, so i added path to the MapKit.js in my index.html, right after the phonegap.js

<script type="text/javascript" src="js/MapKit.js"></script>

then after adding the sample code from the readme inside my App's deviceReady, and calling app.showMap(); gives me this error:

2013-10-10 13:23:09.524 helloWorld[745:60b] CDVPlugin class MapKitView (pluginName: MapKit) does not exist.
2013-10-10 13:23:09.527 helloWorld[745:60b] ERROR: Plugin 'MapKit' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2013-10-10 13:23:09.529 helloWorld[745:60b] -[CDVCommandQueue executePending] [Line 117] FAILED pluginJSON = [
  "MapKit1243294480",
  "MapKit",
  "showMap",
  [
    {
      "lat" : 49.281468,
      "diameter" : 1000,
      "lon" : -123.104446,
      "atBottom" : true,
      "height" : 460
    }
  ]
]

my auto generated config.xml includes this:

    <feature name="MapKit">
        <param name="ios-package" value="MapKitView" />
    </feature>

and interestingly if i console.log(mapKit); i get this in xcode console:

2013-10-10 13:23:09.536 helloWorld[745:60b]  {"options":{"height":460,"diameter":1000,"atBottom":true,"lat":49.281468,"lon":-123.104446},"mapType":{"MAP_TYPE_NONE":0,"MAP_TYPE_NORMAL":1,"MAP_TYPE_SATELLITE":2,"MAP_TYPE_TERRAIN":3,"MAP_TYPE_HYBRID":4},"iconColors":{"HUE_RED":0,"HUE_ORANGE":30,"HUE_YELLOW":60,"HUE_GREEN":120,"HUE_CYAN":180,"HUE_AZURE":210,"HUE_BLUE":240,"HUE_VIOLET":270,"HUE_MAGENTA":300,"HUE_ROSE":330}}

thanks again for all your help!

ok, solved... had to change
<script type="text/javascript" src="phonegap.js"></script>
to
<script type="text/javascript" src="cordova.js"></script>
i cant keep up with these naming conventions...

thanks @imhotep for the help!

I have all the same issues, except up to this last step from @samburgers where he states that he solved the issue by changing to using cordova.js (which I am already doing), @samburgers what does your cordova.js file look like? Are you sure it wasn't something else? Inside my cordova.js file there is nothing that resembles including any sort of mapkit code.

Any ideas @imhotep ?

Thanks for any help!

@cooleo400 cordova.js or cordova_plugins.js are not supposed to have any MapKit code. You just have to include cordova.js in your page as well as the MapKit.js file. There is a sample project inside this plugin, you can just copy to a newly generated project's www folder and see what happens.