簡體   English   中英

Google Maps無法在iPhone / iPad worklight 6.2應用程序上運行

[英]Google Maps not working on iPhone/iPad worklight 6.2 app

我正在為我的組織開發一個應用程序,該應用程序要求在地圖上顯示其辦公室位置,當用戶單擊鏈接應用程序時,將在瀏覽器中打開google map,並顯示用戶當前位置和所選辦公室標記之間的路線。 這在Android應用程序中可以完美運行,但在iPhone / iPad應用程序上則無法運行。 我正在使用以下代碼:

我已經在index.html文件中聲明了google api腳本

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>

以下是location.html文件的代碼

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"   content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
</head>
<body style="display: none; background-color: silver; color: green; font-size: small;">


    <div data-role="main" class="ui-content">
            <div data-role="content" id="contentMap">
                <div id="map_canvas" style="position: absolute !important; top: 10px !important; right: 0; bottom: 5px !important; left: 0 !important;"></div>
            </div>
    </div>
<script src="js/location.js"></script>
</body>
</html>

以下是location.js文件的代碼:

/* JavaScript content from js/location.js in folder common */
function OfficeLocation(latitude,longitude,name,address){
    this.latitude = latitude;
    this.longitude = longitude;
    this.name = name;
    this.address = address;
}

var officeLocationArray = [
                            new OfficeLocation(32.3947198, -90.1457959, "office location 1", "office location 1"),
                            new OfficeLocation(31.7138728, -89.1492813, "office location 1", "office location 1"),
                            new OfficeLocation(32.2777552, -90.1223944, 'office location 1', 'office location 1')
                          ];

// would be used as users current location
var usersLat;
var usersLng;
var youAreHereMarkers; //markers to represent current user location ( blue marker is used). can replace with any image or gifs ( like blue dot gifs)
var map; //
var mapURL; //users location and destination selected by user are stored in this variablse in order to use it to open google map in new browser with route visible
var currentPosition; // will store lat/lng location for google map api. 
var infowindow; //displays information about the location when user clicks marker on map
/**
 * everthing happens here 
 * 
 * on success : getuser location,get new map , add user markers, add win job markers , add marker listeners  that lets you open original google map with direction
 * on failure: get new map, add all winjob marker 
 */
$("#divLocation").on("pageshow", function(event, ui) {
    alert("map initiliaziation started");
    getUsersCurrentLocationAndPopulateMap();
});

/**
 * 
 */
function getUsersCurrentLocationAndPopulateMap() {
    var options = {
              enableHighAccuracy: true,
              timeout: 10000,
              maximumAge: 0
            };
    navigator.geolocation.getCurrentPosition(locationFound, locationNotFound, options);
}

/**
 * creates new map, and adds all marker related information
 * @param pos
 */
function locationFound(pos){
    try{
        var coords = pos.coords;
        usersLat = coords.latitude;//pos.coords.latitude;
        usersLng = coords.longitude;//pos.coords.longitude;
        getNewMap();
        addUsersLocationMarker();
        addAllMarkers();
    }catch (e) {
        alert(e.message);
    }
}

/**
 * user location is not determined.
 * possible gps sensor problem
 * @param err
 */
function locationNotFound(err){
    showAlert("Unable to determine your location.");
    getNewMap();
    addAllMarkers();
    alert('ERROR(' + err.code + '): ' + err.message);

}
/**
 * new map is created
 */
function getNewMap() {
    try{
        var zoomlevel = 7;
        var usersLocation = new google.maps.LatLng(usersLat, usersLng);
        map = new google.maps.Map(document.getElementById('map_canvas'), {
            zoom : zoomlevel,
            center : usersLocation,
            mapTypeId : google.maps.MapTypeId.ROADMAP
        });
    }catch(e){
        alert(e.message);
    }
}

/**
 * place users locatin markers on map and also all win job locations markers
 * based on array provided
 */
function addUsersLocationMarker(){
    try{
        var blueMarker = new google.maps.MarkerImage(
                'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
                new google.maps.Size(37, 34), new google.maps.Point(0, 0),
                new google.maps.Point(0, 19));
        //placing users location map
        //http://maps.google.com/mapfiles/ms/icons/blue-dot.png
        youAreHereMarkers = new google.maps.Marker({
            position : new google.maps.LatLng(usersLat, usersLng),
            map : map,
            animation : google.maps.Animation.BOUNCE,
            title : "You are Here",
            icon : blueMarker//'images/here.png'
        });
    }catch (e) {
        alert(e.message);
    }
}

/**
 * reads all the marker informatin from officeLocationArray and place it on the map as clickable markers
 */
function addAllMarkers() {
    //clickable region
    var shape = {
        coord : [ 1, 1, 1, 20, 18, 20, 18, 1 ],
        type : 'poly'
    };

    // populalte markers on all WIN Job Center location
    var numberOfLocations = officeLocationArray.length;
    for (var i = 0; i < numberOfLocations; i++) {
        var ofcLocation = officeLocationArray[i];

        var flag = new google.maps.MarkerImage(
                'http://googlemaps.googlermania.com/google_maps_api_v3/en/Google_Maps_Marker.png',
                new google.maps.Size(37, 34), new google.maps.Point(0, 0),
                new google.maps.Point(0, 19));
        var myLatLng = new google.maps.LatLng(parseFloat(ofcLocation.latitude), parseFloat(ofcLocation.longitude));
        var marker = new google.maps.Marker({
            position : myLatLng,
            map : map,
            icon : flag,
            shape : shape,
            title : ofcLocation.name + "\n" + ofcLocation.address
        });

        //  listens if user clicks on marker to display infowindow, and eventually driving to google map in new browser
        google.maps.event.addListener(marker,'click',function() {
            try{
                if(infowindow){
                    infowindow.close();
                }
                map.setZoom(8);
                map.setCenter(marker.position);
                var destinationAddress = this.getTitle().split("\n");
                mapURL = "http://www.google.com/maps/dir/'"+ usersLat + "," + usersLng + "'/'"+ destinationAddress[0]+","+ destinationAddress[1] + "'";
                var contentString=destinationAddress[0]+ /*"<br />"+ destinationAddress[1]+*/ "<br/><div><a href='#' onClick='openGoogMap()' > Go to this location </a></div>";
                infowindow = new google.maps.InfoWindow({
                    maxWidth: 200,
                    content : "<div style='overflow:hidden;line-height:1.35;min-width:200px;'>"+contentString+"</div>"
                });

                infowindow.open(map, this);
                //  showAlert(openMapString);
            }catch (e) {
                alert(e.message);
            }
        });
    }
}
/**
 * opens google map in a browser with information appended in mapURL
 */
function openGoogMap() {
    WL.App.openURL(mapURL);
}

任何幫助表示贊賞。

UPDATE

工作燈版本:6.2.0.0

Xcode版本:6

好。 得到了答案。 由於我是在XCode 6中構建應用程序並使用Worklight版本6.2.0.0,所以這就是這段代碼造成問題的原因。 您可以從IBM網站閱讀有關該問題的信息。 要解決此問題,請下載以下修訂包 ,它將您的worklight版本更新為6.2.0.1。 之后,您必須在pathToYourProject \\ YourProject \\ apps \\ yourAppName \\ iphone \\ native \\ yourAppName-Info.plist文件中添加以下條目:

<key>NSLocationAlwaysUsageDescription</key>
<string>Permissions Message for App even when not in use</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Permissions Message for App when in use</string>

生成並重新部署您的應用程序,現在應該可以正常工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM