0

我正在尋找關於如何在Google地圖上顯示興趣點(保存在融合表中)的示例。Google地圖上的Fusion Tables v2 POI:Android示例?

要做到這一點HTML和JavaScript這是相當瑣碎,檢查我的javascript map with fusion tables example

Fusion Tables page containing my POIs

我的目標/問題是如何(需要編碼它的幫助),以達到相同的Android應用中。我對android開發很陌生,並且我已經投入了數小時的基礎知識並檢查文檔和示例。

檢查這個很好Google Maps example for Android我發現開始了(我的測試應用程序是基於這段代碼的)。

Fusion Tables v2 reference(指向Google API用戶端)

Google API Java client samples on github(最過時的:在V1的例子)

到目前爲止,我實現了顯示地圖集中於我的最後已知位置,並顯示出它的標誌。

因爲我無法找到很好的例證,我決定發佈和分享我的調查結果,請參見:firepol/android-google-maps-fusion-tables on github

現在我想顯示從融合表來標記。 我被困在執行請求,我試圖通過谷歌API客戶端。

Google API client example for Android

ActivityFeed feed = listActivities.execute(); 

這裏我的代碼(我已經把裏面的onCreate):

protected void prepareFusion() { 
    // Normally READONLY should be enough (see credential with one scope), but I checked online a console 
    // and I could see a public table only if I would grant both permissions 
    List<String> scopes = new ArrayList<>(Arrays.asList(FusiontablesScopes.FUSIONTABLES, FusiontablesScopes.FUSIONTABLES_READONLY)); 
    credential = GoogleAccountCredential.usingOAuth2(this, scopes); 
    //credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(FusiontablesScopes.FUSIONTABLES_READONLY)); 

    // TODO : get account name automatically 
    // http://stackoverflow.com/questions/35789071/getting-the-gmail-id-of-the-user-in-android-6-0-marshmallow 
    credential.setSelectedAccountName("YOUR_GOOGLE_ACCOUNT"); 

    client = new Fusiontables.Builder(
      transport, jsonFactory, credential).setApplicationName("TestMap/1.0") 
      .build(); 

    try { 
     String tableId = "1774o_WcrqSQlepLXlz1kgH_01NpCJ-6OyId9Pm1J"; 

     Fusiontables.Query.Sql sql = client.query().sql("SELECT FileName,Name,Location FROM " + tableId); 
     //sql.execute(); 
     //java.lang.IllegalStateException: Calling this from your main thread can lead to deadlock 

     Fusiontables.Table.Get table = client.table().get(tableId); 
     table.setFields("items(FileName,Name,Location)"); 
     //table.execute(); 

     // TODO : can't execute like this on main thread as the documentation example "suggests" 
     //https://developers.google.com/api-client-library/java/google-api-java-client/android 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

如果我試圖做同樣的,並呼籲sql.execute()或table.execute ()我得到:

java.lang.IllegalStateException:從您的主線程調用 可能導致死鎖k

所以我有點卡在這裏,我想知道如何從有經驗的谷歌API客戶端的人開始,甚至更好,如果你能幫助我在地圖上得到結果!謝謝。

如何在地圖上顯示融合表POI?

​​

要看到我堅持,並幫助我,我的克隆GitHub庫firepol/android-google-maps-fusion-tables on github,Android Studio中打開它,加入自己的谷歌地圖API密鑰和調試設備。感謝您的建設性意見,答案和幫助。隨意推動Github以及。

回答

0

This commit implements the fusion tables query and shows the resulting POIs on google maps

說明:GoogleAccountCredential是錯誤的,必須與GoogleCredential更換。爲了使這項工作你需要create a service account,角色項目>服務帳戶演員(生成一個私鑰),下載json文件,並將其放置在應用程序/ res/raw/service_account_credentials.json(在我的承諾我指這個文件具有這個確切的名稱,但隨時可以將它命名並使代碼適應您的需要)。

確保在項目的API管理器中啓用Fusion Tables API

我實現了一個派生自AsyncTask的類來解決主線程的問題。

提交中有一些小的重構(位置更改爲LatLng),但就是這樣。

無論誰需要製作一個Android應用程序並放置融合表格POIs在谷歌地圖上都可以克隆github回購站點,並有一些開始(這也是我的問題的最初想法)。

0

在android網絡調用永遠不會在UI /主線程上進行。

嘗試使用異步任務,如果你只是想看到事情的工作或導入像volley/robospice的網絡庫,如果你正在開發一個完整的項目。

+0

Thx。有一個更新的教程或代碼示例使用谷歌api客戶端的異步任務嗎?我會看看也是Robospice等找到一個很好的介紹,以比較它們:https://www.reddit.com/r/androiddev/comments/3d1iim/retrofit_volley_or_robospice_and_jackson_or_gson / – firepol

相關問題