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

解決了我的問題。謝謝您的回答。 –