Javascript 谷歌地图不适用于iPhone/iPad worklight 6.2应用程序

Javascript 谷歌地图不适用于iPhone/iPad worklight 6.2应用程序,javascript,google-maps,jquery-mobile,ibm-mobilefirst,worklight-runtime,Javascript,Google Maps,Jquery Mobile,Ibm Mobilefirst,Worklight Runtime,我正在为我的组织开发一个应用程序,需要在地图上显示其办公室位置,当用户单击链接应用程序时,将在浏览器上打开谷歌地图,并显示用户当前位置和所选办公室标记之间的路线。这在Android应用程序中运行良好,但在iPhone/iPad应用程序中不起作用。我正在使用以下代码: 我已经在index.html文件中声明了google api脚本 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=fals

我正在为我的组织开发一个应用程序,需要在地图上显示其办公室位置,当用户单击链接应用程序时,将在浏览器上打开谷歌地图,并显示用户当前位置和所选办公室标记之间的路线。这在Android应用程序中运行良好,但在iPhone/iPad应用程序中不起作用。我正在使用以下代码:

我已经在index.html文件中声明了google api脚本

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
<!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.html文件的代码

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
<!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);
}
公共文件夹中js/location.js中的JavaScript内容*/ 办公地点功能(纬度、经度、名称、地址){ 这个。纬度=纬度; 这个经度=经度; this.name=名称; this.address=地址; } 变量OfficeLocationaray=[ 新办公地点(32.3947198,-90.1457959,“办公地点1”,“办公地点1”), 新办公地点(31.7138728,-89.1492813,“办公地点1”,“办公地点1”), 新办公地点(32.2777552,-90.1223944,“办公地点1”,“办公地点1”) ]; //将用作用户当前位置 var-usersLat; var-usersLng; var Youarehere标记//表示当前用户位置的标记(使用蓝色标记)。可以替换为任何图像或GIF(如蓝点GIF) var映射// var-mapURL//用户选择的位置和目的地存储在此变量中,以便使用它在新浏览器中打开google地图,并显示路线 var currentPosition;//将为谷歌地图api存储lat/lng位置。 var信息窗口//当用户单击地图上的标记时,显示有关位置的信息 /** *一切都发生在这里 * *成功后:获取用户位置、获取新地图、添加用户标记、添加赢得工作标记、添加标记侦听器,让您可以打开带有方向的原始谷歌地图 *失败时:获取新映射,添加所有winjob标记 */ $(“#divLocation”)。在(“页面显示”上,函数(事件,用户界面){ 警报(“地图初始化已启动”); GetUsersCurrentLocation和PopulateMap(); }); /** * */ 函数getUsersCurrentLocationAndPopulateMap(){ 变量选项={ EnableHighAccurance:正确, 超时:10000, 最大值:0 }; navigator.geolocation.getCurrentPosition(locationFound、locationNotFound、options); } /** *创建新地图,并添加所有与标记相关的信息 *@param pos */ 功能位置已找到(pos){ 试一试{ var coords=pos.coords; usersLat=coords.latitude;//pos.coords.latitude; usersLng=coords.longitude;//pos.coords.longitude; getNewMap(); addUsersLocationMarker(); addAllMarkers(); }捕获(e){ 警报(e.message); } } /** *用户位置未确定。 *可能的gps传感器问题 *@param err */ 函数位置未找到(错误){ showAlert(“无法确定您的位置”); getNewMap(); addAllMarkers(); 警报('ERROR('+err.code+'):'+err.message); } /** *创建新地图 */ 函数getNewMap(){ 试一试{ var zoomlevel=7; var usersLocation=new google.maps.LatLng(usersLat,usersLng); map=new google.maps.map(document.getElementById('map_canvas'){ zoom:zoomlevel, 中心:用户位置, mapTypeId:google.maps.mapTypeId.ROADMAP }); }捕获(e){ 警报(e.message); } } /** *在地图上放置用户位置标记,以及所有赢得工作位置标记 *基于提供的数组 */ 函数addUsersLocationMarker(){ 试一试{ var blueMarker=new google.maps.MarkerImage( 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png', 新的google.maps.Size(37,34),新的google.maps.Point(0,0), 新的google.maps.Point(0,19)); //放置用户位置图 //http://maps.google.com/mapfiles/ms/icons/blue-dot.png youAreHereMarkers=new google.maps.Marker({ 位置:新的google.maps.LatLng(usersLat,usersLng), 地图:地图, 动画:google.maps.animation.BOUNCE, 标题:“你在这里”, 图标:blueMarker/'images/here.png' }); }捕获(e){ 警报(e.message); } } /** *从officeLocationArray读取所有标记信息,并将其作为可单击标记放置在地图上 */ 函数addAllMarkers(){ //可点击区域 变量形状={ 坐标:[1,1,1,20,18,20,18,1], 类型:“poly” }; //在所有WIN作业中心位置上填充标记 var numberOfLocations=OfficeLocationAry.length; 对于(变量i=0;i