使用Phonegap Build后,谷歌地图将不会显示在手机上

Google maps wont display on mobile after using Phonegap Build

本文关键字:显示 手机 Build Phonegap 谷歌地图 使用      更新时间:2023-09-26

我的谷歌地图在Firefox中运行良好,但当我为移动设备构建它时。地图根本无法显示或加载,遗憾的是,我的编码经验和知识都很贫乏,仍然没有找到解决方案。。。有人知道问题出在哪里吗?如果需要,我可以发布更多代码

var map, places, iw;
var markers = [];
var autocomplete;
var defaultLatLng = new google.maps.LatLng(34.0983425, -118.3267434); 
var myLatlng = new google.maps.LatLng(37.783259, -122.402708);
function initialize() {
  var myOptions = {
    zoom: 17,
    //center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  if (navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords
        .latitude, position.coords.longitude);
      map.setCenter(initialLocation);
      map.setZoom(16);
      var marker = new google.maps.Marker({
        position: initialLocation,
        title: "You are here!"
      });
      marker.setMap(map);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  }
  map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);
  places = new google.maps.places.PlacesService(map);
  google.maps.event.addListener(map, 'tilesloaded', tilesLoaded);
  autocomplete = new google.maps.places.Autocomplete(document.getElementById(
    'autocomplete'));
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    showSelectedPlace();
  });
}

在初始化之前需要使用"插件"

即:plugin.google.maps.Map(document.getElementById("Map_canvas");

类似于其他初始化

var map, places, iw;
var markers = [];
var autocomplete;
var defaultLatLng = new plugin.google.maps.LatLng(34.0983425, -118.3267434); 
var myLatlng = new plugin.google.maps.LatLng(37.783259, -122.402708);
function initialize() {
  var myOptions = {
    zoom: 17,
    //center: myLatlng,
    mapTypeId: plugin.google.maps.MapTypeId.ROADMAP
  }
  if (navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new plugin.google.maps.LatLng(position.coords
        .latitude, position.coords.longitude);
      map.setCenter(initialLocation);
  map.setZoom(16);
  var marker = new plugin.google.maps.Marker({
    position: initialLocation,
    title: "You are here!"
  });
  marker.setMap(map);
}, function() {
  handleNoGeolocation(browserSupportFlag);
});
  }
  map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);
  places = new google.maps.places.PlacesService(map);
  plugin.google.maps.event.addListener(map, 'tilesloaded', tilesLoaded);
  autocomplete = new         plugin.google.maps.places.Autocomplete(document.getElementById(
'autocomplete'));
  plugin.google.maps.event.addListener(autocomplete, 'place_changed', function() {
showSelectedPlace();
  });
}

至少

  1. var defaultLatLng=新的google.maps.LatLng(34.0983425,-118.3267434);var myLatlng=新的google.maps.LatLng(37.783259,-122.402708);

应该放在initialize()内

  1. 中心:myLatlng

不应该被评论掉

  1. 应该有以下css样式

    html,正文{高度:100%;}

    地图{

    height: 100%;
    

    }