Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:55:35+00:00 2026-05-26T02:55:35+00:00

I’m developing a Cocoa app using XCode 4. One of the windows has a

  • 0

I’m developing a Cocoa app using XCode 4. One of the windows has a tab view. One of the tabs is supposed to display a Google Maps map of a location. I added a WebView (WebKit framework) to the tab and defined it as an outlet so I can manipulate it with the window controller.

I managed to display a URL (maps.google.com) inside the web view using the following:

    [[mapView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://maps.google.com"]]];

However this is not the result I’m looking for. Ideally I want to have a map view similar as in iPhoto. From this tutorial I understand you will have to have an HTML file on a server to make things work. As my app is a local OS X app (not involved with any server), I was wondering if there are any ways of doing this differently and have the HTML local in de directory of the app (not sure how this would work with the required Google Maps API key which is tied to a URL)?

EDIT:

I’ve solved part of this. You can actually store an HTML file locally (I put mine in the “Supporting Files” folder of my project). You can then access this file using the following code:

    NSString *pagePath;
NSBundle *aBundle = [NSBundle mainBundle];
pagePath = [aBundle pathForResource:@"test2" ofType:@"html"];
// make a file: URL out of the path
NSURL *pageURL = [NSURL fileURLWithPath: pagePath];

Next step is to display the map using the following:

[[mapView mainFrame] loadRequest:[NSURLRequest requestWithURL: pageURL]];

This displays the map inside my WebView. As a starting point I used the sample from the Google Maps API tutorial here. This particular example displays a map centered on Stockholm, Sweden.

The one thing I have not managed to solve is how to access the Javascript function that displays the map (in the above example that would be the initialize() function called using the body onload). For my situation I want to tweak this function to accept two parameters, a longtitude and a latitude, and then call it from my Objective-C object that displays the map. According to the documentation from Apple it is possible to call Javascript from within Objective-C using an instance of WebScriptObject which is accessible through the WebView instance:

    id wso = [mapView windowScriptObject];

Then using the callWebScriptMethod:withArguments: one should be able to execute a Javascript function. However, if I remove the onload of the body tag and call the Javascript initialize() function using the WindowScriptInstance, the map does not show. Anybody an idea what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:55:36+00:00Added an answer on May 26, 2026 at 2:55 am

    The final piece of the puzzle is getting the timing right. You cannot do anything with Javascript until your WebView is done loading. This is signalled back to your controller by sending webView:didFinishLoadForFrame: to your controller. Check out Apple documentation on WebFrameLoadDelegate Protocol Reference here. Your controller should implement some of these methods, depending on the required behaviour (protocol methods are optional).

    Once this method is run, the WebView is ready for work and you can access your Javascript functions in them:

    - (void) webView:(WebView *) webView didFinishLoadForFrame:(WebFrame *) frame {
        NSArray *args = [NSArray arrayWithObjects:
                         [NSNumber numberWithFloat: 59.325225],
                         [NSNumber numberWithFloat:18.0700], nil];
    
        [[webView windowScriptObject] callWebScriptMethod:@"initialize" withArguments:args];
    }
    

    A good point of reference is the CallJS sample app which I dissected to make the whole thing work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.