iphone4使用的離線地圖

來源:互聯網
上載者:User

最近自己製作了幾個iphone4使用的離線地圖,總結一下經驗:

 

1. 原始地圖下載

使用Global Map Download Tool 下載,網上教程很多。

 

2. 轉為iPhone格式

使用GMDL的‘->iPhone' 功能,選擇firmware2.2 & 3,產生MapTiles.sqlitedb。

 

3. 轉為iPhone4格式

使用Mapv4v5Converter轉為iPhone4格式,產生新的MapTiles.sqlitedb。

對於iPhone4,iOS4.2.1,此時產生的MapTiles.sqlitedb的version資訊是不對的(鬱悶)。

由iPhone4地圖應用自身產生的MapTiles.sqlitedb的version表是這樣的:

$sqlite3 MapTiles.sqlitedb

 

SQLite version 3.6.23.2
Enter ".help" for instructions
sqlite> select * from version; 
11|zh_CN
-32519| 
sqlite>

 

而由Mapv4v5Converter產生的MapTiles.sqlitedb是這樣的:

$sqlite3 MapTiles.sqlitedb

 

SQLite version 3.6.23.2
Enter ".help" for instructions
sqlite> select * from version; 
10|zh_CN
0| 
sqlite>

 

其中的locale,即zh_CN也有可能是其他的值。因此,需要將這個表改為與原來一樣

sqlite> update version set version=-32519 where version=0;
sqlite> update version set locale='zh_CN' where version=10;

sqlite> update version set version='11' where version=10;

 

sqlite3可以在iPhone上裝,也可以在PC上裝。

 

4. 地圖初始點

需要用com.apple.Maps.plist確定初始視點。使用經緯度查詢工具確定地圖中心點即可。

從iPhone4的/var/mobile/Library/Preferences目錄下下載com.apple.Maps.plist,使用

plist檔案編輯工具,改為下面內容即可(其中的Latitude和Longitude是北京的經緯度,應替換為

地圖城市中心的經緯度):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LastViewMode</key>
    <integer>0</integer>
    <key>LastViewedLatitude</key>
    <real>39.908711</real>
    <key>LastViewedLongitude</key>
    <real>116.397506</real>
    <key>LastViewedZoomScale</key>
    <real>11</real>
</dict>
</plist>

 

5. 地圖安裝

與每個地圖相關的檔案只有MapTiles.sqlitedb和com.apple.Maps.plist,它們的分別在:

/var/mobile/Library/Caches/Maps/MapTiles 和 /var/mobile/Library/Preferences 路徑下。

因此,只要將製作好的檔案上傳到以上路徑下即可。注意這兩個檔案的許可權應為644,使用者/組為mobile/mobile

(chmod 644 FILE; chown mobile:mobile FILE)。

 

6. 多地圖管理

由於iPhone只能使用一個地圖檔案,因此管理多個離線地圖比較麻煩。

offlinemaps採用的方式是將地圖檔案放在/var/mobile/Media/Maps目錄下,切換地圖是複製到目標目錄。

當然最直接的想法是建立符號連結到目標目錄下,但經過實驗發現不好使(原因不明)。

但是,如果在/var/mobile/Library/Caches/Maps/MapTiles目錄下建立目錄放置地圖檔案,

然後建立符號連結到該目錄下,則不會有問題。因此,可以在/var/mobile/Library/Caches/Maps/MapTiles目錄下

建立不同的目錄,如Beijing,Harbin,放置MapTiles.sqlitedb和com.apple.Maps.plist。

需要使用離線地圖時,使用iFile為MapTiles.sqlitedb建立符號連結到/var/mobile/Library/Caches/Maps/MapTiles目錄下,

並將com.apple.Maps.plist複製到/var/mobile/Library/Preferences 目錄下即可。

 

7. 線上 - 離線切換

如果在線上狀態下使用離線地圖,地圖應用會修改MapTiles.sqlitedb,

產生sqlitedb的journal檔案(原因不明),導致反應遲緩,甚至崩潰(Shame!)。

因此盡量不要在線上狀態使用離線地圖。只需刪掉指向MapTiles.sqlitedb的符號連結即可。

此時地圖應用會產生新的MapTiles.sqlitedb。

 

8. 自動化

我不會iPhone應用開發,希望能有高人將上述方法實現為應用就最好了。

既然offlinemaps是python指令碼程式,搞搞這些應該很簡單啊,

不明白老大們為啥非得copy地圖,期待能搞個好用的東西出來造福群眾啊。


註:

1. Map Enhancer在iPhone4上不好使。

2. iphoneofflinemaps只能copy(orz),多佔一倍空間,不爽。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.