Select to view content in your preferred language

ArcGIS Online Map using URL does not work with PhoneGap 2.7

988
2
05-07-2013 04:12 AM
AlexChen
Occasional Contributor
Hi all,

I wanted to show my public accessible ArcGIS Online map with URL on a simple Hello World PhoneGap project with Eclipse. Eclipse threw out the following error in LogCat.

Web Console:RequestError: Unable to load file: //www.arcgis.com/sharing/rest/content/items/{MapId}?f=json status: 0 at http://serverapi.arcgisonline.com/jsapi/arcgis/3.4compact/:15

Just wondering anyone have had any successful experience with using ArcGIS Online web map with PhoneGap?

Many thanks in advance!

Cheers,
Alex
0 Kudos
2 Replies
SathyaPrasad
Esri Contributor
Use this code in your js app before getting the webmaps:

esri.arcgis.utils.arcgisUrl = esri.arcgis.utils.arcgisUrl.replace("file:", "http:");
0 Kudos
AndyGup
Esri Regular Contributor
Alex,

Thanks to @SathyaPrasad the workaround at this point in time is to force Phonegap/Cordova to use HTTP.

Add the following for web maps:

esri.arcgis.utils.arcgisUrl = esri.arcgis.utils.arcgisUrl.replace("file:", "http:");


And, if you are using the locator (geocoder) widget:

widget._arcgisGeocoder.url = widget._arcgisGeocoder.url.replace("file:", "http:")


Here's a psuedo-code example using the new AMD pattern:

       require(["esri/map","esri/arcgis/utils","esri/dijit/Legend","esri/dijit/Scalebar"],
                function(Map,utils,Legend,Scalebar) {

                    var map = null;
                    utils.arcgisUrl = utils.arcgisUrl.replace("file:", "http:");
                    var mapDeferred = utils.createMap("4778fee6371d4e83a22786029f30c7e1", "mapDiv");
                    mapDeferred.then(function(response) {
                        dojo.byId("title").innerHTML = response.itemInfo.item.title;
                        dojo.byId("subtitle").innerHTML = response.itemInfo.item.snippet;

                        map = response.map;
                ... 
                ...
                ...
                
                }
0 Kudos