Markers and javascript to objective-c communication

47 views
Skip to first unread message

bwise

unread,
Jul 18, 2008, 10:56:32 AM7/18/08
to iphone-map-view
Interesting project, I was shocked to find out how difficult doing map
overlays is going to be. I wonder how yelp did it? Looks like they
might have just brought in a static map page as an image and overlaid
on top of it. It works, but im looking for more...


2 Questions:

1. Think it is possible to load a bunch of markers into the maps
UIWebView? Im new to this project, not sure how difficult that would
be.

2. Think there is anyway to listen in objective-c to have the iphone
application react to user clicks on the markers?



Basile Cornet

unread,
Jul 18, 2008, 11:01:52 AM7/18/08
to iphone-...@googlegroups.com
I have done that for my project.

I've added JS methods in the MapWebView, to place marker, and in the MapView, in
touches end method (almost sure this is in the touches end), I made a call
to a delegate method, that check if the tapping coordinates are corresponding
the coordinate I used to place the marker. It works well.
--
Basile Cornet

Brian Knorr

unread,
Jul 18, 2008, 11:17:58 AM7/18/08
to iphone-...@googlegroups.com
This is great...would you mind sharing some of your code?  Or even better, abstract it to be generic so it can be included in the project?

Also you mentioned "corresponding coordinates"....are you checking the exact coordinates or a range?

-Brian
--
Brian Knorr
www.watij.com

Basile Cornet

unread,
Jul 18, 2008, 11:25:25 AM7/18/08
to iphone-...@googlegroups.com
Since google maps provide function to return pixel coordinate of a point, I check in a range.
x >= (markerX - 20) && x <= (markerX + 20) && y >= (markerY - 20) && y <= (markerY + 20)

I'll try next week to make it generic
--
Basile Cornet

Mahmoud AlGammal

unread,
Jul 18, 2008, 12:23:33 PM7/18/08
to iphone-...@googlegroups.com
On Fri, Jul 18, 2008 at 5:56 PM, bwise <djb...@gmail.com> wrote:

Interesting project, I was shocked to find out how difficult doing map
overlays is going to be. I wonder how yelp did it? Looks like they
might have just brought in a static map page as an image and overlaid
on top of it. It works, but im looking for more...

It's not that difficult. I'm doing that already on top of this component in one of my projects. However, I refrained from having such code hardwired into the component itself because I figured everyone would like to do it his/her own way, so instead, I just kept what I thought should help everyone trying to add this feature to a project. 

2 Questions:

1. Think it is possible to load a bunch of markers into the maps
UIWebView? Im new to this project, not sure how difficult that would
be.
 
I recommend subclassing the MapView, and adding the markers as subviews of it. Of course, whenever the map is zoomed or panned you'd have to update the locations of the markers. This can be done by having the subclass implement the MapWebViewDelegate protocol, and registering itself as the MapWebView's delegate. 

2. Think there is anyway to listen in objective-c to have the iphone
application react to user clicks on the markers?

Sure. If you go by my suggestion above you can add any UIControl (a custom UIButton with an image for example), and rely on the regular Cocoa Touch event handling mechanism. That's how I do it actually.







--
Mahmoud AlGammal
http://blog.gammal.org/

bwise

unread,
Jul 19, 2008, 1:55:45 PM7/19/08
to iphone-map-view
This sounds like what I need. Better if the markers are native objects
on top. Thanks, will dig in and test this out!!!

Is your application live? Id love to see this implementation in
action.

On Jul 18, 12:23 pm, "Mahmoud AlGammal" <mahm...@gammal.org> wrote:

Jordan Redner

unread,
Jul 19, 2008, 2:46:17 PM7/19/08
to iphone-...@googlegroups.com
I second that. I could also use that exact functionality.


On another note, I'm still finding it to be slugging when deployed on
an iPhone. Can anyone think of anything that would help improve
performance? I find when comparing the functionality to something
like Loopt, it's just really slow, and zoom in or out aren't very
respondent.... on the simulator of course everything looks great.


Jordan

Basile Cornet

unread,
Jul 19, 2008, 2:56:39 PM7/19/08
to iphone-...@googlegroups.com
Think the only way to have that working well on iPhone is doing like Loopt or Google.
A database with coordinate information and img number.
So it needs to cut the map in piece of coordinate for each zoom lvl etc...
--
Basile Cornet

Mahmoud AlGammal

unread,
Jul 19, 2008, 3:32:36 PM7/19/08
to iphone-...@googlegroups.com
I think I can release a video or something, but not the code. However, I'll try to find some time to extend the sample application to show how that can be done.

Brad Smith

unread,
Jul 19, 2008, 3:44:49 PM7/19/08
to iphone-...@googlegroups.com
Loading markers is no problem.  You can add them to the map using the standard google maps api, either directly or using a MarkerManager. 

My application has several custom icons.  I define them as GIcons, using a data url for the image so that I cut down on network utilization. 

In order to send a click action there are two approaches I have used.  The first is to set up a polling loop (triggered by aperiodic timer) that queries the javascript, for a variable you set when the icon is clicked, using the stringbyevaluationjavascript method of UIWebview.

The second, better method, is to have the icon, when clicked, is to set  document=action in the javascript.  You can capture this with the the shouldStartLoadWithRequest method of the UIWebView Delegate parse out the action in the query and handle it accordingly.  Have the method return false, and the page won't change (you will need to return true for the inital load of the map.)  Here is a snippet from my application where I implement this logic:

//JAVASCRIPT:
//This is called by the onclick of any custom markers I add
function setMessage(messageToSet)
    {
    document.location = '?showListing='+messageToSet;
    }       
   

//This is from the class that implements the UIWebViewDelegatee Protocal
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *command;
    NSString *query = [request.URL query];
    printf("Should start load with request: %s\n",[query UTF8String]);
    if ([request.URL query] == nil){
        return YES;
    }
   
    command = @"showListing=";
    if ([query hasPrefix:command]){
        NSString *listingID = [query substringFromIndex:12];
        if (listingID){
            TeepeePropertyDetailViewController *propertyDetailViewController = [[TeepeePropertyDetailViewController alloc] init];
            propertyDetailViewController.propertyListing = [applicationController.propertyList getListingWithID: listingID];
            [[self navigationController] pushViewController:propertyDetailViewController animated:YES];
            [propertyDetailViewController release];
        }
    }
   
    else if ([query hasPrefix:@"mapMovedToNewArea"]){
        [[[[UIApplication sharedApplication] delegate] applicationController] mapMovedToNewArea];   
    }
   
    return NO;
}



I hope this helps. 

--Brad Smith
  Frelance iPhone Developer

Jordan Redner

unread,
Jul 20, 2008, 8:00:14 PM7/20/08
to iphone-...@googlegroups.com
Hi. I am trying Brad's technique...

I have the javascript/html rendering such that when you click on the
balloon in a normal browser, it shows a balloon which was tied to the
marker, and in that balloon, there are html links.

Using the MapView component, all the balloons (GMarker objects) render
on the map just fine.

But when I tap on a balloon, the click event doesn't get sent to the mapview.

Do you, or does anyone know how to make the tap or click events go to
the browser or UIWebView so that the javascript that is already there
will work as it does in a browser for marker html?


For others trying to render markers, I added the following javascript
to the source code which is now being returned by my server of
course...

My marker javascript code looks like:

function addMarker(lat, lon, markerTitle, color, timeStamp) {
var point = new GLatLng(lat, lon);
if (color == 'green') {
markerOptions = { title:markerTitle, icon:green };
} else {
markerOptions = { title:markerTitle, icon:red };
}
var marker = new GMarker(point, markerOptions);
map.addOverlay(marker);
points.push(point);

GEvent.addListener(marker,'click', function() {
var bubbleHtml = markerTitle + "<br/>" + timeStamp
+ "<br/>";

bubbleHtml += "<a
href='http://maps.google.com/maps?q=" + lat + "," + lon + "'>map</a>";
map.openInfoWindowHtml(point, bubbleHtml);
});
}


Jordan

Mahmoud AlGammal

unread,
Jul 21, 2008, 4:55:48 AM7/21/08
to iphone-...@googlegroups.com
The touch events don't reach the UIWebView because it's obscured by a transparent view that captures all events. When I started writing the component, my idea was to rely on native Objective-C calls as much as I could, in order to minimize the jumps from Objective-C to Javascript as much as possible. Therefore, I personally add markers are regular UIViews (or a subclass, such as UIButton) to the MapView and rely on the delegate methods to update their locations when the map state changes.

If you want to follow the other technique, I'm sure there's a way to pass touch events from the MapView to the MapWebView. I don't have the documentation handy now, but I'm sure you'll be able to find it easily.

Jordan Redner

unread,
Jul 21, 2008, 11:11:31 AM7/21/08
to iphone-...@googlegroups.com
ok thanks, that makes sense. if others have done this any pointers
would be helpful... if I don't hear anything I'll post what I find...

Brad Smith

unread,
Jul 21, 2008, 3:39:21 PM7/21/08
to iphone-...@googlegroups.com
I should have posted this when I first wrote about the pin dropping.
This took me a long while to figure out, but that was a couple of months ago now, and I forgot all about it.  As Mahmoud mentioned, He wrote his code with a transparent overalay over the UIWeb view to capture touch events in Obj-C land before translating them to javascript to pass on to the map.

To be able to click on the map you need to send the touch event to both the UIWeb view.  (Actually the Webview's private instance of UIWebDocumentView.)  So what I did to store a referance to that was to overide hittest on the Mahmoud's WebView class, and store the result like this:


@interface MapWebView :UIWebView {
    UIView *privateWebDocView;                    //<---Added this as an object to send clicks to
}

//@implementation MapWebView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

{
        self.userInteractionEnabled = YES;
        privateWebDocView = [super hitTest:point withEvent:event];
        privateWebDocView.userInteractionEnabled = YES;
        privateWebDocView.multipleTouchEnabled = YES;
        self.userInteractionEnabled = YES;
        return nil;
}


Now that I have a referance to the WebDocumentView,  I change the event handeling code to the methods in Mahmoud's WebView class:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
...    switch ([touches count]) {
   ...     case 1: {
               //See I added this here:
      ...      [mMapWebView.privateWebDocView touchesBegan:touches withEvent:event];  //<--
         ...   [self resetTouches];
        } break;
...etc



Do the same thing with touchesEnded and you should be in good shape.  You may also want to write some code to make sure a tochesEnded event is fired right away, otherwise when the user hold down their finger to long, the WebView will pop up an annoying tool tip.

--Brad Smith
  Freelence iPhone Developer

Jordan Redner

unread,
Jul 22, 2008, 12:35:04 AM7/22/08
to iphone-...@googlegroups.com
hmmmmm...

I *think* I understand what you are saying to try...

So, I added these methods to the MapWebView class:

- (void) platformTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
}

- (void) platformTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesEnded:touches withEvent:event];
}


then, I added code
to the MapView class to bubble up these events...

switch ([touches count]) {

case 1: {
// potential pan gesture
-----------> [mMapWebView platformTouchesBegan:touches
withEvent:event];
UITouch *touch = [[touches allObjects] objectAtIndex:0];
[self setPanningModeWithLocation:[touch locationInView:self]];
} break;

but, this just crashes each time I try a click or a tap.

hitTest is no longer in the project, so I didn't know what you meant
when you referenced hitTest...

I don't think I'm understanding. It makes sense to try to bubble up
the events to the UIWebView, but I *think* that is what I tried.


thanks for anymore guidance.


Jordan

bwise

unread,
Jul 23, 2008, 2:45:52 PM7/23/08
to iphone-map-view
Brad, I am following your instructions exactly. The only place I am
lost on is

"You may also want to write some code to make sure a tochesEnded event
is fired
right away"

This seems to short circuit any panning action, and the map is dead.
What did I miss?
> On Mon, Jul 21, 2008 at 8:11 AM, Jordan Redner <jred...@gmail.com> wrote:
>
> > ok thanks, that makes sense. if others have done this any pointers
> > would be helpful... if I don't hear anything I'll post what I find...
>
> > On Mon, Jul 21, 2008 at 1:55 AM, Mahmoud AlGammal <mahm...@gammal.org>
> > wrote:
> > > The touch events don't reach the UIWebView because it's obscured by a
> > > transparent view that captures all events. When I started writing the
> > > component, my idea was to rely on native Objective-C calls as much as I
> > > could, in order to minimize the jumps from Objective-C to Javascript as
> > much
> > > as possible. Therefore, I personally add markers are regular UIViews (or
> > a
> > > subclass, such as UIButton) to the MapView and rely on the delegate
> > methods
> > > to update their locations when the map state changes.
>
> > > If you want to follow the other technique, I'm sure there's a way to pass
> > > touch events from the MapView to the MapWebView. I don't have the
> > > documentation handy now, but I'm sure you'll be able to find it easily.
>
> > > On Mon, Jul 21, 2008 at 3:00 AM, Jordan Redner <jred...@gmail.com>
> > >> On Sat, Jul 19, 2008 at 12:44 PM, Brad Smith <bradsmith...@gmail.com>

Brian Weisenthal

unread,
Jul 23, 2008, 3:52:57 PM7/23/08
to iphone-...@googlegroups.com
Nevermind...got it. Was sending the touches end to the wrong object.
Sent it to the mapWebView and that did it.

Too many markers also seem to crush performance...we are switching
gears now to overlay our own native markers.

Brad Smith

unread,
Jul 23, 2008, 4:00:04 PM7/23/08
to iphone-...@googlegroups.com
What I meant there was send a touchesEnded event only the map via the privateWebDocView.  I do this within to touchesBegan Method on the controller.   I admit this is hackish, but it solves the problem of the tool tip windows popping up.  What I show below is what I have done, and it  works, however because that second event is send so fast, clicking on markers with a custom graphical 'down state' doesn't work to well.  What  Should work better is to have a nstimer set up to make the second call, a fraction of a second later.


- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
...    switch ([touches count]) {
  ...     case 1: {
              //See I added this here:
     ...      [mMapWebView.privateWebDocView touchesBegan:toucheswithEvent:event];  //<--
     [mMapWebView.privateWebDocView touchesEnded:toucheswithEvent:event];  //<--Added To suppress automatic info bubble

Jordan Redner

unread,
Jul 23, 2008, 9:25:51 PM7/23/08
to iphone-...@googlegroups.com
Brian,

Can you paste the specific code you have added to bubble up the events please?

thanks so much.

Jordan

Bjarte Stien Karlsen

unread,
Jul 25, 2008, 7:33:42 AM7/25/08
to iphone-map-view
It would be very nice to have support for markers built into the
component itself.

It is too bad really that it is not possible to just import a KML file
into the google.maps app on the phone with custom markers,
descriptions aso.

Very good work on the component!

regards
Bjarte

On Jul 24, 3:25 am, "Jordan Redner" <jred...@gmail.com> wrote:
> Brian,
>
> Can you paste the specific code you have added to bubble up the events please?
>
> thanks so much.
>
> Jordan
>
> ...
>
> read more »

James

unread,
Aug 12, 2008, 11:53:39 AM8/12/08
to iphone-map-view
Hey Jordan,

Did you ever figure this out? I'm stuck on this as well. I've got
Brian's code incorporated as above but the clicks still don't seem to
be passing through.

Thanks! :)

James
> ...
>
> read more »

Jordan Redner

unread,
Aug 12, 2008, 12:38:35 PM8/12/08
to iphone-...@googlegroups.com
No, I didn't.

Jordan

Paul

unread,
Aug 12, 2008, 2:42:42 PM8/12/08
to iphone-map-view
Hi All,

I had this feature working up until yesterday. Now it seems I can't
get it to work. Did google change something in their code??? I can
get clicks through on other items except on the markers.

Anyone else having this new issue with markers?

Paul



On Aug 12, 11:53 am, James <jrbos...@gmail.com> wrote:
> Hey Jordan,
>
> Did you ever figure this out? I'm stuck on this as well. I've got
> Brian's code incorporated as above but the clicks still don't seem to
> be passing through.
>
> Thanks! :)
>
> James
>
> On Jul 23, 9:25 pm, "Jordan Redner" <jred...@gmail.com> wrote:
>
> > Brian,
>
> > Can you paste the specific code you have added to bubble up the events please?
>
> > thanks so much.
>
> > Jordan
>
> ...
>
> read more »

madh...@hotmail.com

unread,
Aug 12, 2008, 7:00:24 PM8/12/08
to iphone-map-view
yes, same here. I had it working. now it is not. I suspect google
changed some thing and it is not working on webkit correctly.

anybody else have more info on this ? I hope google fixes this, else
I have to re-implement it using native controls as markers and I don't
want to get there.
> ...
>
> read more »

madh...@hotmail.com

unread,
Aug 12, 2008, 9:40:30 PM8/12/08
to iphone-map-view
ok I figured it out. It appears the last two release of google maps
api is broken w.r.t markers on safari on iPhone. Markers are not
responding to click/mousedown events.

the solution is to use version 2.121 or earlier. For this you can not
user wenear url in MapWebView.m loadMap() method. You have to use your
own server and load the specified version of google maps api :

<script src="http://maps.google.com/maps?
file=api&amp;v=2.121&amp;key=.......

On Aug 12, 4:00 pm, "madha...@hotmail.com" <madha...@hotmail.com>
wrote:
> ...
>
> read more »

Paul Murphy

unread,
Aug 13, 2008, 7:03:06 AM8/13/08
to iphone-...@googlegroups.com
good work...I just downgraded and now am working fine....thanks

----- Original Message ----
From: "madhancr@hotmail..com" <madh...@hotmail.com>
To: iphone-map-view <iphone-...@googlegroups.com>
Sent: Tuesday, August 12, 2008 9:40:30 PM
Subject: Re: Markers and javascript to objective-c communication


ok I figured it out. It appears the last two release of google maps
api is broken w.r.t markers on safari on iPhone. Markers are not
responding to click/mousedown events.

the solution is to use version 2.121 or earlier. For this you can not
user wenear url in MapWebView.m loadMap() method.. You have to use your

own server and load the specified version of google maps api :

<script src="http://maps.google.com/maps?
file=api&v=2.121&key=.......
> > > > > Nevermind....got it. Was sending the touches end to the wrong object.
> > > > >>>>>> course....

Brad Smith

unread,
Aug 12, 2008, 5:34:37 PM8/12/08
to iphone-...@googlegroups.com
Hello there.

I have been busy for the past two weeks. First with iPhone Dev camp
in San Francisco, then with Defcon in Las Vegas, where I just returned
from this morning.

Once I am caught up on critical projects, I will try to write up a
better guide to how I am able to send events to both the Objective-C
view the is overlaid as well as to the Web Page that is inside the
UIWebView.

I should be able to get to that tomorrow or the next day.

--Brad Smith
Freelance iPhone Developer

P.S.
My first name is Brad, not Brian

paul

unread,
Aug 26, 2008, 10:33:49 PM8/26/08
to iphone-map-view
Hi there.

I'm quite confused by the discussion. (hitTest.. plotting marker with
delegate) Someone please help me with this?

My question is really simple:
I have the overlay loaded onto my own server. I direct the app to view
it and so how do i go about clicking those marker already on the web?

Paul

On Aug 13, 5:34 am, Brad Smith <bradsmith...@gmail.com> wrote:
> Hello there.
>
> I have been busy for the past two weeks.  First with iPhone Dev camp  
> in San Francisco, then with Defcon in Las Vegas, where I just returned  
> from this morning.
>
> Once I am caught up on critical projects, I will try to write up a  
> better guide to how I am able to send events to both the Objective-C  
> view the is overlaid as well as to the Web Page that is inside the  
> UIWebView.
>
> I should be able to get to that tomorrow or the next day.
>
> --Brad Smith
>    Freelance iPhone Developer
>
> P.S.
>    My first name is Brad, not Brian
>
> On Aug 12, 2008, at 9:38 AM, Jordan Redner wrote:
>
>
>
> > No, I didn't.
>
> > Jordan
>
> > On Aug 12, 2008, at 10:53 AM, James <jrbos...@gmail.com> wrote:
>
> >> Hey Jordan,
>
> >> Did you ever figure this out? I'm stuck on this as well. I've got
> >> Brian's code incorporated as above but the clicks still don't seem to
> >> be passing through.
>
> >> Thanks! :)
>
> >> James
>
> >>>>>> To be able toclickon the map you need to send the touch event  
> >>>>>>>>> But when I tap on a balloon, theclickevent doesn't get sent
> >>>>>>>>>> In order to send aclickaction there are two approaches I
> ...
>
> read more »

Alexey Blinov

unread,
Aug 28, 2008, 4:40:57 AM8/28/08
to iphone-map-view
I am not using the MapWebView class, but instead just load a page with
a map into a UIWebView. I assume this is not making much difference.

I have tried to solve the problem with the markers and I too came to
the conclusion that it all really hangs in the API version, namely:
— In version 2 I can successfully pan around, however, no taps are
recognised either in the iPhone or the Emulator;
— In version 2.121 I can tap the map to create the markers and tap the
markers to bring up the info cloud, but I can't pan around or drag
markers around. It just registers a click event with the point where I
started dragging and creates a marker there.
Naturally in Safari everything works fine.

Has anyone discovered an API version that would support both tapping
and dragging?

Antoine

unread,
Sep 16, 2008, 12:56:39 PM9/16/08
to iphone-map-view
Your App crashes because you have a loop by forwarding events to
mMapWebView.

As Brad said, you must forward began and ended events directly to the
private instance of UIWebView.

So you must use hitTest to get this reference.
> > On Mon, Jul 21, 2008 at 8:11 AM, Jordan Redner <jred...@gmail.com> wrote:
>
> >> ok thanks, that makes sense.  if others have done this any pointers
> >> would be helpful...  if I don't hear anything I'll post what I find...
>
> >> On Mon, Jul 21, 2008 at 1:55 AM, Mahmoud AlGammal <mahm...@gammal.org>
> >> wrote:
> >> > The touch events don't reach the UIWebView because it's obscured by a
> >> > transparent view that captures all events. When I started writing the
> >> > component, my idea was to rely on native Objective-C calls as much as I
> >> > could, in order to minimize the jumps from Objective-C to Javascript as
> >> > much
> >> > as possible. Therefore, I personally add markers are regular UIViews (or
> >> > a
> >> > subclass, such as UIButton) to the MapView and rely on the delegate
> >> > methods
> >> > to update their locations when the map state changes.
>
> >> > If you want to follow the other technique, I'm sure there's a way to
> >> > pass
> >> > touch events from the MapView to the MapWebView. I don't have the
> >> > documentation handy now, but I'm sure you'll be able to find it easily.
>
> >> > On Mon, Jul 21, 2008 at 3:00 AM, Jordan Redner <jred...@gmail.com>
> >> >> On Sat, Jul 19, 2008 at 12:44 PM, Brad Smith <bradsmith...@gmail.com>
> >> >> > On Fri, Jul 18, 2008 at 7:56 AM, bwise <djbw...@gmail.com> wrote:
>
> >> >> >> Interesting project, I was shocked to find out how difficult doing
> >> >> >> map
> >> >> >> overlays is going to be. I wonder how yelp did it? Looks like they
> >> >> >> might have just brought in a static map page as an image and
> >> >> >> overlaid
> >> >> >> on top of it. It works, but im looking for more...
>
> >> >> >> 2 Questions:
>
> >> >> >> 1. Think it is possible to load a bunch of markers into the maps
> >> >> >> UIWebView?
>
> ...
>
> plus de détails »

Antoine

unread,
Sep 16, 2008, 1:06:02 PM9/16/08
to iphone-map-view
I'm using UIWebView and it works.

You just need to forward some events to the private instance of
UIWebDocumentView, as Brad said previously.

My code works, so, hope this helps:

Just add theses methods in MapWebView.m:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
self.userInteractionEnabled = YES;
privateWebDocView = [super hitTest:point withEvent:event];
privateWebDocView.userInteractionEnabled = YES;
privateWebDocView.multipleTouchEnabled = YES;
self.userInteractionEnabled = YES;
return nil;
}

- (void) platformTouchesBegan:(NSSet*)touches withEvent:
(UIEvent*)event {
[[self privateWebDocView] touchesBegan:touches withEvent:event];
}

- (void) platformTouchesEnded:(NSSet*)touches withEvent:
(UIEvent*)event {
[[self privateWebDocView] touchesEnded:touches withEvent:event];
}

Update UIResponder methods in MapView.m:
//------------------------------------------------------------------------------
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
mTouchMovedEventCounter = 0;

NSSet *allTouches = [event allTouches];

// Forwarding tap events
switch ([touches count]) {
case 1:
[mMapWebView platformTouchesBegan:touches withEvent:event];
break;
}
//

switch ([allTouches count]) {
case 1: {
// potential pan gesture
UITouch *touch = [[allTouches allObjects] objectAtIndex:
0];
[self setPanningModeWithLocation:[touch
locationInView:self]];
} break;

case 2: {
// potential zoom gesture
UITouch *touch0 = [[allTouches allObjects] objectAtIndex:
0];
UITouch *touch1 = [[allTouches allObjects] objectAtIndex:
1];
CGFloat spacing =
[self eucledianDistanceFromPoint:[touch0
locationInView:self]
toPoint:[touch1
locationInView:self]];
[self setZoomingModeWithSpacing:spacing];
} break;

default:
[self resetTouches];
break;
}
}

//------------------------------------------------------------------------------
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {

NSSet *allTouches = [event allTouches];

// Forwarding tap events
switch ([touches count]) {
case 1:
[mMapWebView platformTouchesEnded:touches withEvent:event];
break;
}
//
switch ([allTouches count]) {
case 1: {
UITouch *touch = [[allTouches allObjects] objectAtIndex:
0];
switch (touch.tapCount) {
case 1:
if (mOnClickHandler)
[self performSelector:mOnClickHandler];
break;

case 2: {
CGPoint pixel = [touch locationInView:self];
[mMapWebView
panToCenterWithPixel:GPointMake(pixel.x, pixel.y)];
} break;
}
} break;
}

[self resetTouches];

Brother

unread,
Sep 17, 2008, 12:58:19 PM9/17/08
to iphone-map-view
I have included the code and all compiles. When I click on a marker,
nothing happens on the map though.
Question: In the javascript code embedded in the page I am loading,
should I define a marker event with the "click" event or the
"mouseover" event? Does it make any difference?

Thanks

Dr. Chuck

unread,
Sep 17, 2008, 10:37:56 PM9/17/08
to iphone-map-view
I've inserted code into MapView.m that allows you to drag a single
marker around (it can easily be extended to drag any marker(s)).
HOWEVER, you must provide the functions that enable this dragging on
the JS side. I've posted the modified MapView.m here:

http://www.smartscorecard.com/iPhone-dragging-test/MapView.m

In addition, a sample URL that contains the called JS functions is
here:

http://www.smartscorecard.com/iPhone-dragging-test/index.html

You can examine the source code to see the JS functions that Mapview.m
accesses to implement the dragging. The basic methodology is this:

1. When the code detects a possible pan in touchesBegan(), it makes a
call to the JS function hit_test().
2. If hit_test() returns TRUE, that means the marker was hit, so it
sets the dragging BOOL to TRUE.
3. Now, during the pan in touchesMoved(), instead of panning, it calls
the JS function move_dragging_marker().
4. At the end of the pan in touchesEnded(), it moves the marker to its
final position by calling the JS function move_fixed_marker().

Cheers, Chuck

Antoine

unread,
Sep 18, 2008, 4:56:19 PM9/18/08
to iphone-map-view
Yes you have to.

like this:

GEvent.addListener( gMarker, "click", function( e) {
// doing something
});

Cameron Tuckerman

unread,
Oct 1, 2008, 3:05:48 PM10/1/08
to iphone-map-view
If I have a marker already on my map through the api, would these
allow the mapview app to click on them to open the bubble? If so, how
would I implement these into the app?

Cameron Tuckerman

unread,
Oct 1, 2008, 12:16:10 PM10/1/08
to iphone-map-view
Sorry for my naivety upfront.

I am attempting to be able to have my markers be "clickable" and this
thread seems to have some demo code that would do this, however I
cannot seem to get any of it to work. Would I simply copy the code
into the MapWebView.m file and compile? Or are there some other things
that would have to be set. Whenever I add it I get errors when I
build. Thanks for the help!

On Sep 16, 1:06 pm, Antoine <antoine.pou...@gmail.com> wrote:
> > markers around. It just registers aclickevent with the point where I

sanil

unread,
Oct 4, 2008, 7:56:16 AM10/4/08
to iphone-map-view
Can I capture the click of the marker to carry out a view transition
in my iphone i.e. I want to capture the click event on the marker and
load a different view on the iphone

On Oct 1, 9:16 am, Cameron Tuckerman <tuckerma...@onepulsemedia.com>
wrote:

Dr. Chuck

unread,
Oct 7, 2008, 8:36:28 AM10/7/08
to iphone-map-view
Yes, you can. I already posted code that you can repurpose that does
a hit test to see if a marker is hit:

http://groups.google.com/group/iphone-map-view/browse_thread/thread/bb075cd0f85c4595/237d0bb03386e926?lnk=gst&q=hit_test#237d0bb03386e926

A side note: the JS code for moving the marker is badly written--I
keep clearing the overlays and constructing a new marker whereas you
should just be moving the marker.

HTH, Chuck

paul

unread,
Oct 12, 2008, 3:28:13 PM10/12/08
to iphone-map-view
What about an array of markers? I figured I should use XML to draw the
markers instead of using a KML overlay so I can use the hittest for
all the markers on the map.

it doesn't work for me and I'm still trying to figure out a way. has
anyone successfully done it?

On Oct 7, 8:36 pm, "Dr. Chuck" <chuck....@gmail.com> wrote:
> Yes, you can.  I already posted code that you can repurpose that does
> a hit test to see if a marker is hit:
>
> http://groups.google.com/group/iphone-map-view/browse_thread/thread/b...

beaver

unread,
Oct 24, 2008, 11:05:46 AM10/24/08
to iphone-map-view

I'm trying to do exactly the same thing... but it doesn't seems to
work for me?
Did you managed to get it to work?
> > > > — In version 2.121 I cantapthe map to create the markers andtapthe

aka

unread,
Oct 24, 2008, 1:56:16 PM10/24/08
to iphone-...@googlegroups.com

Earlier on it was reported that the latest version of Google Maps and
MapWebView have a problem with this. I am using Version 2.121 of
Google Maps with no problems. If I use the latest version of Google
Maps I can't get marker touches to work. I could do what someone
proposed earlier with some JS code but I am using the Google Maps
InfoWindow and need to get the touches to it also. Anyone have any
ideas why this is not working?


Paul

beaver

unread,
Oct 24, 2008, 10:45:37 PM10/24/08
to iphone-map-view
Touch and gesture work for me... just that I want the single touch (or
click) event to be sent to the webview so that the GEvent script for,
say a marker, can be triggered. Anyone have any idea?

beaver

beaver

unread,
Oct 25, 2008, 4:11:12 AM10/25/08
to iphone-map-view
I figured it out.... Brad's code work! The key is sending the
touchBegan to WebView.

Thanks to all!

Cheers

Mike

unread,
Oct 28, 2008, 10:35:25 PM10/28/08
to iphone-map-view
Ok, I'm still not getting this...

I am pushing markers onto the map through the JS API. That's working
fine. But now I need a way to let the single clicks through to the web
component so if I click on a marker it can show the marker name.

I am NOT tracking the markers inside of JS at all. I'm just placing
them programmatically and that's it.

I really need to get this working like today! Any help is
appreciated...

--Mike

Dr. Chuck

unread,
Oct 29, 2008, 11:38:37 AM10/29/08
to iphone-map-view
Earlier in this thread, I posted code that allows you drag a single
marker around. You can modify that code so that tapping on a marker
shows the marker name instead of initiating the drag sequence. You'll
have to do three things:

1. keep the markers in an array
2. modify the JS function hit_test() so that it cycles through the
array and, when it finds a marker, do the name-displaying.
3. modify how the iPhone app code handles the JS call to hit_test()
accordingly.

Chuck

paul

unread,
Oct 31, 2008, 1:13:22 PM10/31/08
to iphone-map-view
Hi there,

Everything works in this thread, thanks alot.

However, JS bring the performance of App down to its knee. hope they
can rectify the webview to run js more quickly.

Paul

Brad Smith

unread,
Oct 31, 2008, 1:54:50 PM10/31/08
to iphone-...@googlegroups.com
Glad I could help out.  I was wondering if that technique was still working.   I hacked that up a couple versions of the google api ago - and I know some of the touch event handling is behaving differently now.

--Brad Smith
 iPhone Developer
 (415) 640-8536
Reply all
Reply to author
Forward
0 new messages