2016-01-05 58 views
1

我使用Ti.map我的鈦的iOS/Android的如何添加「當前位置按鈕」(航標)在蘋果地圖上Ti.map

至於Android的

有被自動添加當前位置按鈕

enter image description here

(我不知道這是什麼按鈕被調用,所以我稱之爲「當前位置按鈕」現在是這樣。

但是對於iOS,

當前位置按鈕不會自動添加。

有沒有辦法在蘋果地圖上添加此按鈕?

這些是我的代碼。

var mapView = Map.createView({ 
     mapType:Map.NORMAL_TYPE, 
     userLocation:true, 
     region: {latitude:35.699058, longitude:139.326099,  
     latitudeDelta:0.01, longitudeDelta:0.01}, 
     animate:false, 
     regionFit:true, 
     userLocation:true, 
    }); 

我讀this文章和發現。

- To use the `userLocation` property in iOS 8 and later, add either the 
     [`NSLocationWhenInUseUsageDescription`](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW26) 
     or 
     [`NSLocationAlwaysUsageDescription`](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18) 
     key to the iOS plist section of the project's `tiapp.xml` file. 
      <ti:app> 
       <ios> 
        <plist> 
         <dict> 
          <key>NSLocationAlwaysUsageDescription</key> 
          <string> 
           Specify the reason for accessing the user's location information. 
           This appears in the alert dialog when asking the user for permission to 
           access their location. 
          </string> 
         </dict> 
        </plist> 
       </ios> 
      </ti:app> 

所以我在我的tiapp.xml中添加了這個,並且提示警告顯示正確。

但是,仍然沒有出現當前位置按鈕。

在iOS的默認蘋果地圖應用程序中,左下方有當前位置按鈕(箭頭標記)。


感謝評論。

我的第一個想法是錯誤的。 'userLocation:true'與我稱之爲'當前位置按鈕'的按鈕沒有關係

所以我手動創建了另一個按鈕並連接Ti.Geolocation。

var locationButton = Ti.UI.createButton({ 
     backgroundImage:'/images/check.png', 
     right:'15dp',width:'32dp',height:'32dp' 
    }); 
    mapView.add(locationButton); 
    locationButton.addEventListener('click',function(){ 
     Ti.API.info("get current location");  
     if (Ti.Geolocation.locationServicesEnabled) { 
      Titanium.Geolocation.getCurrentPosition(function(e) { 
       if (e.error) { 
        Ti.API.error('Error: ' + e.error); 
       } else { 
        Ti.API.info(e.coords); 
        mapView.setLocation({ 
         latitude:e.coords.latitude, longitude:e.coords.longitude, animate:false, 
         latitudeDelta:0.01, longitudeDelta:0.01 
        }); 
       } 
      }); 
     } else { 
      alert('Please enable location services'); 
     } 
    }); 

enter image description here

現在它工作得很好,感謝您的幫助。

+0

不同的按鈕是你所尋求的一個。 Android上的一個原生Google地圖。所以約翰的回答實際上是正確的。 –

+0

啊,我看到這個按鈕原生只有android,對不對?所以我必須自己製作另一個按鈕才能跳到當前的用戶位置? – whitebear

回答

3

當你創建你需要設置額外的屬性地圖:

require('ti.map').createView({mapType:MapModule.SATELLITE_TYPE, userLocation:true}); 

這應該做的伎倆;-)

/約翰

+0

感謝您的回覆!我有一些問題。 – whitebear

+0

它將是SATELLITE_TYPE視圖。將當前位置按鈕添加到法線貼圖是不可能的?即使我添加此代碼userLocation按鈕不會出現,MapModule.SATELLITE_TYPE是Map.SATELLITE_TYPE的拼寫錯誤? – whitebear

+0

我在文章中添加了我的源代碼。 – whitebear

相關問題