How to Use StageWebView.loadString() to Show Google Maps on AIR for iOS

Why won't a Google Maps map rendered using the Javascript API display on iOS when using a StageWebView? It works perfectly fine on Android and in the AIR simulator, but for some reason, it just won't render on iOS devices. Interestingly, I can view the generated HTML in Safari which adds to the confusion.

Here is an example of the HTML that I am generating dynamically within the app:

<!DOCTYPE HTML>
<html style="width:100%; height:100%; margin: 0; padding: 0;">
    <head>
<title></title>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function(e){
            var myLatlng = new google.maps.LatLng( 0,0);
            var mapOptions = {
                zoom: 18,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: true,
                zoomControl: true,
                zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.DEFAULT
                }
            }
            var map = new google.maps.Map(document.getElementById("maps") , mapOptions);
            geocoder = new google.maps.Geocoder();
            geocoder.geocode( { "address": "90 South Kyrene, Chandler, AZ 85226" }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                      map: map,
                      position: results[0].geometry.location
                    });
                }
            });
       });
    </script>
    </head>
    <body style="width:100%; height:100%; margin: 0; padding: 0;">
        <div id="maps" style="width:100%; height:100%;  margin: 0; padding: 0;"></div>
    </body>
</html>

I'm attempting to load this HTML using

StageWebView.loadString( html, "text/html" );
. Do you have any insights into why it fails to render? Loading URLs works without issues, so next, I will try saving the HTML to disk and loading it from there instead of loadString.

This has been tested on both iOS 6 and iOS 7, as well as with AIR 3.8 and 3.9.

EDIT: After saving the HTML file to disk and then loading it via StageWebView.loadURL(), the map displays correctly. However, I am still left wondering why using loadString() does not work as expected.

Answer №1

It seems like the issue is related to iOS javascript sandboxing and how the StageWebView API functions. In the past, I attempted something similar with the Twitter service in order to bypass pin authentication, but it appears that iOS does not permit the execution of JavaScript from within your app.

To address this, one possible solution is to utilize a native webview extension. The stagewebviewbridge offers a loadString method that can work alongside JavaScript.

If you are looking for map browsing capabilities, you may want to consider using a native extension. For iOS-exclusive apps, options like air-maps-ane or the MapQuest API could be worth exploring. Personally, I have successfully integrated them into both Android and iOS applications.

Answer №2

If you encounter issues with your webpage rendering, consider removing the "<!DOCTYPE HTML>" tag. I faced a similar problem in the past and found that once I removed this tag, the page displayed correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to modify a particular value buried within a JavaScript object?

Within my node project, I am working with a JavaScript object like the one shown below: that.responseData = { fields: { id: { label: 'ID', value: objectRecord.id, info: '', ex ...

Capturing a res.send(404) error in ExpressJS during production: Tips and tricks

Can middleware handle errors like 404 and 500 when they are returned this way? exports.index = function(req, res) { res.send(404); } In production, I would want to display a custom missing page for these errors. However, my error handler middleware doe ...

What is the best way to ensure that my image completely occupies the div?

I am facing a challenge in creating a hero image that would completely fill the div on my webpage. Despite setting the width and height to 100%, the image seems to only occupy half of the space. Check out the CSS and HTML code snippet here. div.hero{ ...

Eliminate screen flickering during initial page load

I've been developing a static website using NuxtJS where users can choose between dark mode and default CSS media query selectors. Here is the code snippet for achieving this: <template> <div class="container"> <vertical-nav /> ...

Having trouble removing cells in UICollectionViewController

Currently, I am utilizing UICollectionViewController and attempting to use deleteItems in a loop for selected items. The code snippet looks like this: for item in (collectionView?.indexPathsForSelectedItems)! { let cell = self.collect ...

Is there a way to show a fallback message for unsupported video file formats?

When incorporating a video element on my webpage, I typically use the following code: <video src="some source" controls> Error message </video> Based on my knowledge, the "Error message" will only appear if the browser does not support the ...

Implementing CodeIgniter's HMVC structure to dynamically update data using AJAX functionality

Recently, I came across an AJAX function in an open-source code that caught my attention. function edit_person(id) { save_method = 'update'; $('#form')[0].reset(); // reset form on modals //Ajax Load data from ajax $.ajax({ ...

How to extract IDs from a URL in Angular

I'm facing an issue with retrieving the first id from an image URL. Instead of getting the desired id, I am receiving the one after the semicolon ("id" = 1). I have tried various methods but haven't been successful in resolving this issue. Any su ...

Arrange the row information in the MUI DataGrid in order to prepare it for exporting to CSV or Excel

Is there a way to organize row data for exporting to CSV or Excel with the MUI DataGrid? Take a look at my code snippet for the toolbar. slots={{ noRowsOverlay: NoDataComponent, noResultsOverlay: NoDataComponent, toolbar: ( ...

Navigating to a particular section within a ScrollView by clicking a button

Hello there! I'm facing a situation where I have a view controller with a menu displaying various items. When a user clicks on one of the menu items, I want it to navigate directly to the corresponding content within a UIScrollView in another view co ...

The variable being attempted to read is undefined, resulting in an error

I am attempting to access the title property of the first item in an array of objects. Interestingly, when I manually enter the following code in Chrome's JavaScript developer console: hello.example.array[0].title I successfully retrieve the title. ...

Angular 2: Dynamically Adjusting View Components Based on URL Path

Apologies for the unconventional title. I struggled to come up with a better one. My goal is to develop an application with a simple 3-part structure (header / content / footer). The header should change based on the active route, where each header is a s ...

Using AngularJS to dynamically populate a select list with options from a JSON

Trying to populate a select option with data from a simple JSON array. For example, I want to create a country selector. Each country in the array has an ID and a name, among other fields that are not needed. Essentially, I aim to set one value in the val ...

What is the process for browserifying the net.Socket module in Node.js?

I'm exploring ways to connect and query my MS SQL database from JavaScript in a web browser (specifically Chrome, not IE as I don't want to use ActiveX controls). I came across this Node library called Tedious and Browserify to help with this tas ...

"Revamping data structures with Redux, organized entities, and advanced merging techniques

Currently, my setup involves Redux, React, and Lodash working together to manage a normalized entities store. The challenge I'm facing is that whenever I incorporate new entities into a redux reducer using lodash's merge function, the references ...

The model fails to update when a blur event occurs

I am a beginner with Angular2 and I am currently working on creating a reactive form, specifically an interactive date input field. Here is my HTML code: <div class="date ui-input"> <input type="text" name="dateD" [ngModel]="model.date | dat ...

Can the CSS property "float: none;" interfere with the Javascript function "ng-click"?

This particular issue is quite strange. Setting "float: none;" appears to be preventing the execution of Javascript (ng-click). new.html.haml (where "float: none;" is located) .container{ng: {controller: 'sample_1_controller'}} %nav.bread.m ...

Downloading an empty excel file in PHP using iframes

I am trying to create a frame with a header that includes buttons for listing, PDF, and Excel options. The data from the database is displayed under the header, and everything works fine with the listing option. However, when I attempt to download an Excel ...

JSON.stringify selectively ignores certain object properties

Here's an easy example. function Person() { this.name = "Ted"; this.age = 5; } persons[0] = new Person(); persons[1] = new Person(); JSON.stringify(persons); If I have a list of people objects and want to convert them into JSON format with only ...

Is there a way to connect two classes based on two separate conditions in Vue.js?

I am currently developing a compact checkout stepper using Vue version 2.x.x. The item that is actively being processed should be marked with the class name "active", while all previous items should have the class name "completed", as depicted below: ...