0

谷歌地图显示在浏览器中,但是当我运行命令 ionic run android 它成功地建立并启动应用程序,但一切工作正常,除了谷歌地图没有错误在chrome://inspect它只是说DEVICE READY FIRED AFTER 630 ms但没有错误为谷歌地图。我确实在console.developers.google.com上注册了应用程序,获得了密钥并在www/index.html的头部使用它,但仍然没有任何更改。请帮助谢谢你。 home.ts(Map函数是这个文件里面)谷歌地图的问题 - 离子2

// Get the current location 
    Geolocation.getCurrentPosition().then((position) => { 
    // Set latitude and longtitude variable 
    this.lat = position.coords.latitude; 
    this.long = position.coords.longitude; 

    // This function will get the name of the city where user is located 
    this.getCityName(this.lat, this.long); 

    // this function sets up the google map 
    let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 

    let mapOptions = { 
    center: latLng, 
    zoom: 11, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var mapi = new google.maps.Map(this.mapDiv.nativeElement, mapOptions); 
    // Below code is provided by a ai pollution control website (http://aqicn.org/faq/2015-09-18/map-web-service-real-time-air-quality-tile-api/) 
    // haven't changed anything in below code copied as it is from web 
    var waqiMapOverlay = new google.maps.ImageMapType({ 
       getTileUrl: function(coord, zoom) { 
         return 'http://tiles.aqicn.org/tiles/usepa-aqi/' + zoom + "/" + coord.x + "/" + coord.y + ".png?token=_TOKEN_ID_"; 
       }, 
       name: "Air Quality", 
    }); 
    // Insert above received data into map 
    mapi.overlayMapTypes.insertAt(0,waqiMapOverlay); 

`

回答

0

可能是你的地图是没有得到坐标(position.coords.latitude,position.coords.longitude),这就是为什么你的地图是不是渲染。尝试使用navigator.Geoloaction.getCurrentPosition ...或检查是否需要任何插件来获取用户地理位置。 &宁愿给一些后备坐标。

this.lat = position.coords.latitude || "21.1610858"; 
this.long = position.coords.longitude || "79.0725101"; 
+0

解决了我的问题。谢谢您的回答。 –