mapkit & phonegap 0.9

263 views
Skip to first unread message

hanger

unread,
Feb 3, 2010, 4:10:02 AM2/3/10
to phonegap
I (finally) integrated mapkit into the latest iphone/phonegap

WARNING: this code is still in test, it has not been reviewed.
Javascript wrapper still has to be written, for now it is direct call
to objectivec code.
WARNING 2: it is only for iphone
Follow discussion :
http://groups.google.com/group/phonegap/browse_thread/thread/b6b4f50398a3d114/008e9371b28975c8?q=openmap&lnk=ol&

Javascript Usage:
0) to init PhoneGap.exec("Map.init")
1) To add points
PhoneGap.exec
("Map.addPoint",latitude,longitude,title,subtitle,"purple","processmapclick
('"+data[i].nid
+"')");
2) to display the map
PhoneGap.exec("Map.center",geoParams.lat,geoParams.long,0.4,0.4);
3) to reset and hide the map (I call it via a tabbar)
PhoneGap.exec("Map.reset")

To integrate:
1) begin as usual : http://phonegap.pbworks.com/Getting+Started+with+PhoneGap+(iPhone)
2) go into phonegap-iphone folder
3) replace map.h & map.m with
http://www.programmers.ch/phonegap/Map.h
http://www.programmers.ch/phonegap/Map.m
4) ..don't know if it is necessary -> open phonegaplib project &
rebuilt it
5) go into phonegap-iphone folder (& type make)
6) reinstall the generated pkg
... that's it ....

Canvin

unread,
Feb 3, 2010, 4:52:24 AM2/3/10
to phonegap
Hello,
first of all, thank you for this code.
i try it, but i have a problem during compilation of my main
project :

Undefined symbols:
".objc_class_name_MKMapView", referenced from:
literal-pointer@__OBJC@__cls_refs@MKMapView in libPhoneGapLib.a
(Map.o)
".objc_class_name_MKPinAnnotationView", referenced from:
literal-pointer@__OBJC@__cls_refs@MKPinAnnotationView in
libPhoneGapLib.a(Map.o)
ld: symbol(s) not found

Could you help me ?

Canvin.

On 3 fév, 10:10, hanger <mkalb...@gmail.com> wrote:
> I (finally) integrated mapkit into the latest iphone/phonegap
>
> WARNING: this code is still in test, it has not been reviewed.
> Javascript wrapper still has to be written, for now it is direct call
> to objectivec code.
> WARNING 2: it is only for iphone

> Follow discussion :http://groups.google.com/group/phonegap/browse_thread/thread/b6b4f503...


>
> Javascript Usage:
> 0) to init PhoneGap.exec("Map.init")
> 1) To add points
> PhoneGap.exec
> ("Map.addPoint",latitude,longitude,title,subtitle,"purple","processmapclick
> ('"+data[i].nid
> +"')");
> 2)  to display the map
> PhoneGap.exec("Map.center",geoParams.lat,geoParams.long,0.4,0.4);
> 3) to reset and hide the map (I call it via a tabbar)
> PhoneGap.exec("Map.reset")
>
> To integrate:
> 1) begin as usual :http://phonegap.pbworks.com/Getting+Started+with+PhoneGap+(iPhone)
> 2) go into phonegap-iphone folder

> 3) replace map.h & map.m withhttp://www.programmers.ch/phonegap/Map.hhttp://www.programmers.ch/phonegap/Map.m

hanger

unread,
Feb 3, 2010, 5:03:44 AM2/3/10
to phonegap
oups ..
I forgot to mention that you have to include the mapkit framework
(right click on the project and add existing framework)

> > 3) replace map.h & map.m withhttp://www.programmers.ch/phonegap/Map.hhttp://www.programmers.ch/pho...

Canvin

unread,
Feb 3, 2010, 5:42:30 AM2/3/10
to phonegap
ok it works well.

Now i'll try to play with it. I'll post my progress (like add polygon
and Javascript wrapper).

Canvin.

Todd Blanchard

unread,
Feb 3, 2010, 6:30:25 AM2/3/10
to hanger, phonegap
That's really cool - thank you so much for doing that. But there are some major bugs in that version.  I have some improved code and JS wrappers nearly done.

As one major bug that drove me nuts I set up a timer to continually re-center the map every second.  Here's the center: code so... 

who can tell me what value latitudedelta will have if the user does not pass it from the js?

clue - nobody :-)
- (void) center:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
{
	
	NSUInteger argc = [arguments count];
	float longitude,latitude,longitutedelta,latitudedelta;
	
	if (argc > 0) latitude = [[arguments objectAtIndex:0] floatValue];
	if (argc > 1) longitude = [[arguments objectAtIndex:1] floatValue];
	if (argc > 2) latitudedelta = [[arguments objectAtIndex:2] floatValue];
	if (argc > 3) longitutedelta = [[arguments objectAtIndex:3] floatValue];
	
	NSLog(@"map:center");
	/*
	 NSLog(@"lattitude %@",latitude);
	 NSLog(@"longitude %@",longitude);
	 NSLog(@"latitudedelta %@",latitudedelta);
	 NSLog(@"longitutedelta %@",longitutedelta);
	 */
	MKCoordinateRegion region;
	MKCoordinateSpan span;
	span.latitudeDelta=latitudedelta;
	span.longitudeDelta=longitutedelta;
	CLLocationCoordinate2D location;
	if (latitude!=0){
		location.latitude=latitude;
		location.longitude=longitude;
	} else {
		location=mapView.userLocation.coordinate;
	}
	
	region.span=span;
	region.center=location;
	[mapView setRegion:region animated:TRUE];
	[mapView regionThatFits:region];
	UIViewController* c = [super appViewController];
	
	[c.view insertSubview:mapView atIndex:1];
	canReset=true;
}

When run in a timer, calling center with just lat and long, the map changes zoom levels like a drunken pilot.
Please consider the following fix to center:


- (void) center:(NSMutableArray*)arguments withDict: 
(NSMutableDictionary*)options; 
    NSUInteger argc = [arguments count];     
    MKCoordinateRegion region = [mapView region]; 

    NSLog(@"setCenter currentRegion is: (%f, %f) span: (%f, %f)",region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta);

    

    if(argc > 0 && [[arguments objectAtIndex:0] doubleValue] != 0.0) region.center.latitude = [[arguments objectAtIndex:0] doubleValue];
    if(argc > 1 && [[arguments objectAtIndex:1] doubleValue] != 0.0) region.center.longitude = [[arguments objectAtIndex:1] doubleValue];

    

    NSLog(@"argc is %d",[arguments count]);

    

    if (argc > 2 && [[arguments objectAtIndex:2] doubleValue] != 0.0) region.span.latitudeDelta=[[arguments objectAtIndex:2] doubleValue]; 
    if (argc > 3 && [[arguments objectAtIndex:3] doubleValue] != 0.0) region.span.longitudeDelta=[[arguments objectAtIndex:3] doubleValue];

    NSLog(@"setCenter newRegion is: (%f, %f) span: (%f, %f)",region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta);

    NSLog(@"map:center"); 

    if(argc > 3)
    {
        [mapView setRegion:region animated:YES];
    }
    else
    {
        [mapView setCenterCoordinate:region.center animated:YES];
    }

and this enhancement

-(void)setMapType:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
{
    id type = [arguments count] ? [arguments lastObject] : nil;
    if([type isEqualToString: @"hybrid"])
    {
        mapView.mapType = MKMapTypeHybrid;
    }
    else if([type isEqualToString: @"satellite"])
    {
        mapView.mapType = MKMapTypeSatellite;
    }
    else if([type isEqualToString: @"standard"])
    {
        mapView.mapType = MKMapTypeStandard;
    }
    else 
    {
        mapView.mapType = MKMapTypeHybrid;
    }
}

I can file a bug if you like.

Also, if anybody is working on file - please stop and email me. I just need a couple days testing and the reader interface, complete with hellacious state machine described in the linked standards document and no arbitrary limit on file size, will be done. :-)

-Todd Blanchard


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Shazron Abdullah

unread,
Feb 3, 2010, 6:40:23 AM2/3/10
to Todd Blanchard, Jesse MacFadyen, phonegap
Hi Todd,
Actually Jesse MacFadyen has done a lot of work on the File API for iPhone PhoneGap. It follows the w3c working draft API. I believe its already in the Edge code, but I am not sure. I am cc'ing him on this email. For example, the audio recording stuff for iPhone PhoneGap is considered incomplete since it is going to be reworked to use the File API.

Shaz

hanger

unread,
Feb 3, 2010, 6:51:09 AM2/3/10
to phonegap
HI,
That was one of the issue
- to make it more generic
- to manage "seriously" the errors ;-)

Ok, for the "continually re-center the map", I think you
missunderstood the way to use
PhoneGap.exec("Map.center",geoParams.lat,geoParams.long,0.4,0.4); is
called only once, (after you added all points)
To say it quickly : only "addPOint" is called multiple times

If you forget the long/lat delta, probably it will generate a
segfault, default values should be added.

Good idea for the maptype.

For publication & people working on the file ... that's a good
question . Seems that Shazron is triing to find out. I published
this because there were people asking for such feature, but I didn't
get any feed backs from the phonegap team.
I wish if it could be intergrated into the edge repository, but it's
not up to me. So for now ... I published it here ... future will tell
us if there will be a more clever way to work on that shared code ...
Marc

> >http://groups.google.com/group/phonegap/browse_thread/thread/b6b4f503...

Canvin

unread,
Feb 3, 2010, 6:52:57 AM2/3/10
to phonegap
Great works Todd,

hope you release the js wrapper soon :).

Canvin

> >>http://groups.google.com/group/phonegap/browse_thread/thread/b6b4f503...

Todd Blanchard

unread,
Feb 3, 2010, 7:00:36 AM2/3/10
to hanger, phonegap
OK, the iPhone map application has this little blue button in the bottom left on the toolbar that causes it to continually track your location and occasionally recenter the map if your location drifts off the edge. So....how am I supposed to implement that feature with this api without my change?

Todd Blanchard

unread,
Feb 3, 2010, 7:06:24 AM2/3/10
to Shazron Abdullah, Jesse MacFadyen, phonegap
OK, I have deadlines and they are SOOON so anything I find half assed, I'm fixing.

You guys are moving much too slowly for me and are doing a poor job of communicating your intentions through the list and the bug tracker.
Stuff I filed mid last week hasn't even been assigned until just now and you seem to be hinting and new direction for some mechanisms, but you're doing a lousy job explaining the future.

Not cool. WTF is the "new EventBroadcaster mechanism"?

Seriously, at this point I'm considering simply forking because what works is fine (like audio) and we seem to be having a lot of duplicated effort on the stuff that is half baked like file.

File was a huge amount of work and I've just finished it (about to start testing).

I'm happy to upload my current state for your examination. But I'm getting the idea that PhoneGap is a hobby for nitobi and for me it has just become my job. I've got clients and deliverables and field tests in 3 weeks. So whatever "sort of works" is fine with me. Whatever is "just a placeholder" needs urgent attention. Moreso than any kind of grand "rethinking of notifications".

That's my $.02. Please improve your project communication. This isn't your private toy anymore.

Todd Blanchard

unread,
Feb 3, 2010, 7:28:58 AM2/3/10
to Canvin, phonegap

hanger

unread,
Feb 3, 2010, 7:36:34 AM2/3/10
to phonegap
Adding my comments on this.

Isn't the the aim of having versions ?

mapkit or file integration could be considered as "extra
functionnalities" and could be implemented using 0.x edge git.
While Nitobi (or whatever) could work in extra "core" functionnalities
or refactoring or setting up a new framework in a new branch that
would end up as a new version of phonegap (1.x).

Whatever, it's not the first time I ask ... HOW TO CONTRIBUTE ...

More over there was an strange issue when using the tabbar. It was
calling (resetfavorite ) etc .. I added the following lines but it's
just a VERY DIRTY workaround .. my deadline was for yesterday .. no
time to do a clean work

- (void) resetfavorite:(NSArray*)arguments withDict:(NSDictionary*)
options;
- (void) resetabout:(NSArray*)arguments withDict:(NSDictionary*)
options;
....

> >>>http://groups.google.com/group/phonegap/browse_thread/thread/b6b4f503...

hanger

unread,
Feb 3, 2010, 7:44:58 AM2/3/10
to phonegap
I would suggest to "cleverly" manage your trigger.
(store location in the js part, and only call map.center when distance
is > that a given delta)

Dogzilla

unread,
Feb 3, 2010, 7:44:25 AM2/3/10
to phonegap
Todd,

I am evaluating various iphone rapid development tools and also find
the ad-hoc approach of the PhoneGap team somewhat frustrating. The
lack of a clear roadmap and documentation have proved very unsettling
when deciding to commit to this approach on anything more than a hobby
level. Unfortunately, PhoneGap does seem to offer the best balance of
low barrier to entry and feature set, and since I will eventually be
handing these custom app development projects to others, it seems I'm
stuck with PhoneGap.

I just wanted to take a moment to thank you for releasing your code.
Given the lack of a real native mapping implementation in PhoneGap,
this will hopefully bridge the gap until whenever PhoneGap can
implement something themselves. If I uncover any bugs, how would you
like to hear about them?

Now if only I could just figure out why navigational elements aren't
working I could finally finish this damn app. Hopefully I won't have
to punt and drop down into Obj-C.

Todd Blanchard

unread,
Feb 3, 2010, 7:49:19 AM2/3/10
to hanger, phonegap
Yes, versions is OK. But do not break existing working code for the sake of "neatness".

As far as I'm concerned, you can close my ticket "Media does not call completion callbacks". I fixed it. It works great. Changing it over now to use some not yet introduced NSNotificationCenter clone will NOT make me happy if it breaks my existing code. This is what I really worry about.

PG has users who are (almost) shipping stuff on tight deadlines (notably ME). DO NOT BREAK IT because you've dreamed up "a better way".

Assign bugs as soon as they come in. I still think it is inexcusable that there was no bug stating that "file basically only kind of works a little for one specific case of reading text" until I filed it a couple days ago and then set out to fix it, only to learn that someone else has been working on it for a couple months?

Gosh, I sure wish I had that 20 hours of development back then (of which, I'm starting hour 21 - probably I should go get some sleep and stop being my extra cranky sleep deprived self).

I'm gonna try reading my audio file and then go get some sleep.

-Todd Blanchard

Todd Blanchard

unread,
Feb 3, 2010, 7:52:21 AM2/3/10
to Dogzilla, phonegap

On Feb 3, 2010, at 4:44 AM, Dogzilla wrote:
> I just wanted to take a moment to thank you for releasing your code.
> Given the lack of a real native mapping implementation in PhoneGap,
> this will hopefully bridge the gap until whenever PhoneGap can
> implement something themselves. If I uncover any bugs, how would you
> like to hear about them?

Post to list or email me. PG is now my full time job. :-) We'll be starting android development in a couple weeks too.

FWIW, I spent some time trying to get google maps v3 playing nice with jqtouch - there's a really weird bug that is keeping it from working and its caching behavior isn't nearly as good as mapkit, so I think mapkit is definitely the way to go.

-Todd Blanchard

Dogzilla

unread,
Feb 3, 2010, 7:57:11 AM2/3/10
to phonegap
Interesting. I'm also using JQTouch to create the interface, but that
was just for a quick demo interface and was planning on refactoring it
out once I can track down the bug keeping the PG navbar and toolbar
from working. I have another mapping hack posted here running already
- dumping to the built in mapping app isn't really a solution. Haven't
tried yours yet, but it sounds like just the ticket.

hanger

unread,
Feb 3, 2010, 8:16:04 AM2/3/10
to phonegap
with the current code jqtouch based tabbar nav will not work, because
mapkit take 100% of the screen. So using the "native" tabbar is much
easier.

You can probably resize the mapkit view created in map::init

Canvin

unread,
Feb 3, 2010, 10:17:48 AM2/3/10
to phonegap
Hello;

add this code to add the blue dot (mapView.showsUserLocation=true; )
with your current location otherwise there is an exception.

In Map.m

(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:
(id <MKAnnotation>) annotation{
...
if ([annotation class] == MKUserLocation.class) {
return nil;
}
}

Canvin.

hanger

unread,
Mar 8, 2010, 9:19:23 AM3/8/10
to phonegap
Hello,
I just downloaded the latest git version, this mapkit code is not
present. Any chance that it will be integrated.
Rem: It was embeded in my app, accepted by Apple (not yet announced,
because not yet published ...)

ChrisB

unread,
Apr 30, 2010, 7:34:30 AM4/30/10
to phonegap
Hi,

Has anyone got a simple example project with index.html, javascript.js
etc. that when you click a button, it asks if it can use your
location, then opens the mapkit google map inside the App? So I can
learn how to use it.

Thank you,

Chris.

muc089

unread,
May 20, 2010, 6:06:09 AM5/20/10
to phonegap
is there any possibility to display the <div class="toolbar"><a
class="back button" href="#">back</a><h1>Results</h1></div>
using mapkit?

thx adrian

or how to integrate a individual styled(backgroundimage) navbar with
only a back button
in objective-c programmatically?


need some help... deadline Tuesday!!!



On 30 Apr., 13:34, ChrisB <chris.bo...@rowleysit.com> wrote:
> Hi,
>
> Has anyone got a simple example project with index.html, javascript.js
> etc. that when you click a button, it asks if it can use your
> location, then opens the mapkit google map inside the App?  So I can
> learn how to use it.
>
> Thank you,
>
> Chris.
>
> On Mar 8, 3:19 pm, hanger <mkalb...@gmail.com> wrote:
>
> > Hello,
> > I just downloaded the latest git version, this mapkit code is not
> > present.  Any chance that it will be integrated.
> > Rem: It was embeded in my app, accepted by Apple (not yet announced,
> > because not yet published ...)
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

muc089

unread,
May 21, 2010, 8:22:13 AM5/21/10
to phonegap
just resized the new webview, so the old div shows up at the top.
thx for the info.

Dave Tao

unread,
Jul 15, 2010, 2:53:16 AM7/15/10
to phonegap
Hi Muc,

I have to ask, :P

how did you resize the webkit view?

Dave.
Reply all
Reply to author
Forward
0 new messages