iphone sdk map

Discussion in 'iPhone/iPad Programming' started by Narmer, May 16, 2008.

  1. macrumors newbie

    Joined:
    May 16, 2008
    #1
    Hi,

    How can I add google maps control to my applicacion?

    Thanks
     
  2. macrumors newbie

    Joined:
    May 19, 2008
    #2
    You can't, not really. There are no hooks for integrating into the google maps bit that apple ships the iPhone with. Also the licensing agreements for free use of the google maps API indicate that whatever you build must be freely available and it must be used in the context of a web browser. You might be able to get around this by hosting a google maps interaction inside a WebView but I don't know how much you can then go and integrate that with the rest of your application (like, I don't know if you can plot data from the phone on the map and cause code to run on the phone as a result of something being taped or moved on the map) *shrug*

    Other than that you might be able to get an enterprise subscription to google maps that will let you embed it in your app but you'd probably end up having to rewrite all the map caching and pixel -> lat/long conversions etc yourself. I think they google maps enterprise license runs around 10k as well.
     
  3. macrumors newbie

    Joined:
    Apr 21, 2008
    #3
    There is maybe a solution, you can look here :

    http://code.google.com/p/iphone-google-maps-component/

    mahm create a "MapView", which is an UIView, "over" a UIWebView, provide some functionnality such as zoom or moving.

    And the WebView "translate" action from the UIView in javascript.

    So if you want more than zooming, or moving, you should have to implements the other methods. That's why i'm going to try, since I need to add pin, and things like that.
     
  4. macrumors newbie

    Joined:
    May 19, 2008
    #4
    thanks for pointing that out, I had somehow missed it getting announced

    if it's really like the android mapview then it should allow you to do some basic stuff like overlays (I just finished a project where we did some pretty extensive hacking with the MapView) but, of course, it's hard to tell without playing with the code

    anyway, thanks again
     
  5. thread starter macrumors newbie

    Joined:
    May 16, 2008
    #5
    Thanks!!

    I'm going to try it!!!


    Best regards,
     
  6. macrumors newbie

    Joined:
    May 26, 2008
    #6
    It's easy to add overlays

    I'm the author of that project, and I'd like to tell you that adding extra features, such as overlays, should be trivial. It was indeed inspired by Android's MapView, but I chose to stick to the Javascript API in naming the methods. There's even a generic method for calling any JS maps method that doesn't have an Objective-C wrapper yet. I'm using the component in a separate project I'm working on, and I actually need to add support for overlays beside other features as well. Naturally, when those features will be added, I'm going to update the Google Code project.
     
  7. macrumors newbie

    Joined:
    Aug 27, 2008
    #7
    Google Maps Project Update?

    I was wondering if there was still an updated version of this project in the works?

    Also, I'm relatively new to Objective-C and development in general and was curious as to how I could implement overlays to customize the existing project to suit my needs.

    Firstly, I'd like to create tappable markers on the map that can pull up driving directions from the phone's current location.

    Any ideas? Thanks in advance!
     
  8. macrumors member

    Joined:
    Feb 21, 2007
    #8
    do the google maps terms of service still apply when using this api? can i, for instance, use this MapView in an app that i'm going to charge for on the app store?
     
  9. macrumors regular

    Joined:
    Jul 28, 2008
    #9
    please share some ideas for overlay

    Hi gammal,

    Thanks a lot for such nice feature added.

    I would appreciate you giving me some hints for adding overlays in this mapview.

    please

    regards
    Jagat
     
  10. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #10
    You could try placing a UIView over it, setting opaque to NO, clear the view's rect; then drawing your overlay.
     
  11. macrumors regular

    Joined:
    Jul 28, 2008
    #11
    again problem

    This map seems to have accessed http://www.enear.com/iphone-test/ ...

    Cant I use it for google maps ?

    I tried changing the url to google maps, but it resulted the screen being white. If i use enear ... iphone-test, then how can I specify lattitude and longitude of my choice ?

    thanks and regards
    Jagat
     
  12. macrumors regular

    Joined:
    Jul 28, 2008
    #12
    uiview

    secondly,

    UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
    myView.center = self.center;
    self.iView = myView;
    [myView release];
    [self addSubview:iView];


    I understand i will have to do something like this. But I want to display that view only when I tap on the map. on that location
    please guide me how to do that. again on second tap it should hide

    regards
    Jagat
     
  13. macrumors regular

    Joined:
    Jul 28, 2008
    #13
    image overlay

    I am trying to display an image overlay over the mapview. I changed the code to following, map displays but the image does not display. image displays if i draw the same code in blank view

    please help

    if (! (self = [super initWithFrame:frame]))
    return nil;

    self.onClickHandler = nil;
    self.autoresizesSubviews = YES;
    self.multipleTouchEnabled = YES;

    mMapWebView = [[[MapWebView alloc] initWithFrame:self.bounds] autorelease];
    //[self addSubview:mMapWebView];

    overlayView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 150.0)];
    overlayView.image = [UIImage imageNamed:mad:"spongebg.jpg"];
    //[self.overlayView setAlpha:0.5];
    overlayView.center = self.center;
    [overlayView setOpaque:YES];
    [self addSubview:eek:verlayView];

    [self resetTouches];

    return self;
     
  14. macrumors regular

    Joined:
    Jul 28, 2008
    #14
    oops

    correction!

    //[self addSubview:mMapWebView];

    this line is not commented ... still it is not showing image on top of the webview

    Jagat
     
  15. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #15
    Could the layering be an issue? Perhaps try addSubview: positioned: relativeTo: to make sure the overlay is in front of the map view?

    Edit - ignore the above, that's Mac-only. Look at the iPhone view class docs, there are methods that can order the subviews for you - if that's the issue. I don't want to give any iPhone specific details with the NDA still in place! ;)
     
  16. macrumors regular

    Joined:
    Jul 28, 2008
    #16
    no luck

    it seems positioned : relativeto is not there in iphone sdk. tried

    [self bringSubviewToFront:eek:verlayView]; in touches ended, but when i tap and release nothing happens !
     
  17. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #17
    Some things you could try:

    Debug the code, and see if overlayView is actually allocated.
    Also check if imageNamed: is actually returning a valid image.
    Maybe you could try making the overlay a subview of the mapview, instead of a subview of "self" in the code above.
    You could try using a setNeedsDisplay to force the overlay view to redraw.
     
  18. macrumors regular

    Joined:
    Jul 28, 2008
    #18
    not yet

    tried everything u said, even tried making it

    window addsubview

    :(... no luck !
     
  19. macrumors regular

    Joined:
    Jul 28, 2008
    #19
    got it

    I was able to show an view as overlay, by adding it as a separate view in the window.

    thanks and regards
    Jagat
     
  20. macrumors newbie

    Joined:
    Apr 18, 2008
    #20
    Hi guys,


    I am new to this plateform and I need to integrate the google map in one of my iphone project. I have downloaded the project from given link, but I need to highlight the current location where I am. Please let me know how can I point this google map to current location by using latitude and longitude values.


    Thanks & Regards,
    Ranjit Singh
     
  21. macrumors newbie

    Joined:
    Sep 30, 2008
    #21
    I am wondering how to specify position of overlay?

    We have the center location, but we don't know the size...

    Also, even we do , do we have to calculate the overlay position based on the map by ourselves? It means every time user moves the map, or rezoom, we have to redraw the overlay?
     
  22. macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #22
    Oh, so in order to get maps, you have to call external API? No wonder why the applications with maps were so slow.
     
  23. macrumors member

    Joined:
    Aug 9, 2008
    #23
    In case it helps, I am using static google maps, although it does not provide the zooming and other functionality, it does go very quick and allow you to create overlays (basic).
     
  24. macrumors 6502

    Joined:
    Jun 21, 2008
    #24
    Likewise, I have a need to embed the map functionality inside of an app I'm writing at work. Basically I want the map in the top 2/3 of the screen, and a table on the bottom 1/3. I need to be able to have pushpins show up on the map at specific locations (based on the data in the table).

    Couple questions:

    1) how does one go about putting the pushpins or icons or something like that onto the map?

    2) Is there a way to add this component into the Interface Builder Palette?

    3) I noticed in the code for the MapView that there's a call to:

    "http://maps.google.com/iphone-test?width=%d&height=%d&zoom=%d"

    If #1 has to be done via KML, how do I get the KML injected into the page? Don't I have to host the KML somewhere else? (sorry, I have only very limited experience dealing with Google Maps/Earth.)

    Any help is appreciated. I'm on a tight deadline to get this all working....

    --Mike
     
  25. macrumors 6502

    Joined:
    Jun 21, 2008
    #25
    Wow, it seems like the author of this is totally out of the loop...

    I've been playing/fighting with this Map View all day and am having several annoying headaches...

    I'm just experimenting with the example app that came in R12.

    I made the appDelegate also be a delegate for the MapWebView:

    So in MapViewAppDelegate.h:

    @interface MapViewAppDelegate : NSObject <UIApplicationDelegate, UIWebViewDelegate, MapWebViewDelegate>

    then in MapViewAppDelegate.m, in applicationDidFinishLaunching():

    [mapView.map setDelegate:self];

    I then implemented the following:

    - (void) mapZoomUpdatedTo: (int)zoomLevel
    {
    NSLog(@"Zoom level is now: %d",[mapView.mMapWebView getZoom]);
    }
    - (void) mapCenterUpdatedToLatLng: (GLatLng)latlng
    {
    GLatLng centerpoint = [mapView.mMapWebView getCenterLatLng];
    NSLog(@"Center Lat = %f Long = %f", centerpoint.lat, centerpoint.lng);
    }
    - (void) mapCenterUpdatedToPixel: (GPoint)pixel
    {
    GPoint centerpoint = [mapView.mMapWebView getCenterPixel];
    NSLog(@"Center Pt x,y = %d,%d",centerpoint.x,centerpoint.y);
    }

    - (void)webViewDidFinishLoad: (UIWebView *)webView
    {
    if(loadcounter==0)
    {
    GLatLng center;
    center = [mapView.map getCenterLatLng];
    NSLog(@"Current Center is: %f, %f",center.lat,center.lng);

    center.lat = 37.137740;
    center.lng = -76.652384;

    [mapView.map setCenterWithLatLng:center];
    [mapView.map setMapType:G_HYBRID_MAP];
    [mapView.map setZoom:7];
    loadcounter++;
    }
    else if(loadcounter==1)
    {
    GLatLng center;
    center.lat = 37.137740;
    center.lng = -76.652384;

    [mapView.map setCenterWithLatLng:center];
    loadcounter++;
    }
    else
    NSLog(@"Finished Loading Page...");
    }



    My intention was to try to get the map to be centered on a specific point once the map loads up.

    Unfortunately, I'm seeing the zoom level change, and the map type changes to Hybrid correctly, but I'm not seeing the map change to the specified center location. If I take that same code that is trying to set the center, and copy it into the MapView's touchesEnded method, if I try to move the map, it immediately re-centers on the point specified.

    What am I doing wrong??? How do I get the map to start up at the point I want???!?!

    Additionally, it doesn't seem like any of the MapWebView delegate methods are ever getting invoked.

    Help!!!

    And has anyone figured out a way to overlay touchable icons onto the map at specific Lat/Long points? I need a way to push and update some icons at specific Lat/Long points, and when you touch them have the display flip to another view that has detailed data about that item at that location.


    And is there any way to get this to show up in the Interface Builder so I can make the Map not take up the whole display? I really want to add a toolbar of buttons at the bottom so the user can recenter the display, etc.

    Any help would be GREATLY appreciated!!!

    --Mike
     

Share This Page