首页 \ 问答 \ Google地图上的Fusion Tables v2 POI:Android示例?(Fusion Tables v2 POIs on Google Maps: Android example?)

Google地图上的Fusion Tables v2 POI:Android示例?(Fusion Tables v2 POIs on Google Maps: Android example?)

我正在寻找一个关于如何在谷歌地图上显示兴趣点(保存在融合表中)的示例。

要在html和javascript中做到这一点,这是相当微不足道的,检查我的JavaScript地图与融合表的例子

请参阅包含我的POI的Fusion Tables页面

我的目标/问题是如何(在编码时需要帮助)在Android应用程序中实现相同目标。 我对android开发很陌生,并且我已经投入了数小时的基础知识并检查文档和示例。

检查这个非常好的谷歌地图示例Android我已经发现开始(我的测试应用程序是基于此代码)。

Fusion Tables v2参考 (指向google api客户端)

github上的Google API Java客户端示例 (大多数过时:v1上的示例)

到目前为止,我已经实现了显示以我最后一个已知位置为中心的地图并在其上显示标记。

因为我找不到这方面的好例子,所以我决定发布并分享我的发现,请参阅: github上的firepol / android-google-maps-fusion-tables

现在我想显示来自融合表的标记。 我被困在执行请求,我试图通过谷歌API客户端。

适用于Android的Google API客户端示例

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:从你的主线程调用这个会导致死锁

所以我有点卡在这里,我想知道如何从有经验的谷歌API客户端开始,如果你能帮助我在地图上得到结果更好! 谢谢。

如何在地图上显示融合表POI?

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker to Zurich Oerlikon and move the camera
    mMap.addMarker(new MarkerOptions().position(mDefaultLatLng).title("Zurich Oerlikon"));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
            mDefaultLatLng, 13));

    // TODO: add fusion tables POIs
}

要查看我卡在哪里并帮助我,请在github 上将我的github repo firepol / android-google-maps-fusion-tables克隆,在Android Studio中打开它,添加您自己的Google Maps API密钥并在设备上进行调试。 感谢您的建设性意见,答案和帮助。 随意推动Github以及。


I'm looking for an example on how to display points of interest (saved in fusion tables) on a google map.

To do this in html and javascript it's quite trivial, check my javascript map with fusion tables example

See Fusion Tables page containing my POIs

My goal/question is how (need help in coding it) to achieve the same in an Android app. I'm new to android development and I already invested hours for the basics and checking documentation and examples.

Check this very good Google Maps example for Android I've found to get started (my test app is based on this code).

Fusion Tables v2 reference (points to google api client)

Google API Java client samples on github (most outdated: examples on v1)

So far I achieved to display a map centered on my last known location and to show a marker on it.

Because I couldn't find good examples for this, I decided to publish and share my findings, see: firepol / android-google-maps-fusion-tables on github

Now I'd like to show markers coming from fusion tables. I'm stuck at executing the request, which I try to do via google api client.

Google API client example for Android

ActivityFeed feed = listActivities.execute();

Here my code (which I've put inside 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();
    }
}

If I try to do the same and call sql.execute() or table.execute() I get:

java.lang.IllegalStateException: Calling this from your main thread can lead to deadlock

So I'm kinda stuck here and I'd like to know how to proceed from somebody who has experience with the google api client, even better if you can help me to get the result on the map! Thank you.

How to display the fusion tables POIs on the map?

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker to Zurich Oerlikon and move the camera
    mMap.addMarker(new MarkerOptions().position(mDefaultLatLng).title("Zurich Oerlikon"));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
            mDefaultLatLng, 13));

    // TODO: add fusion tables POIs
}

To see where I'm stuck and help me, clone my github repo firepol / android-google-maps-fusion-tables on github, open it in Android Studio, add your own Google Maps API Key and debug on your device. Thanks for your constructive comments, answers and help. Feel free to push on github as well.


原文:https://stackoverflow.com/questions/41912999
更新时间:2024-03-11 18:03

最满意答案

代表实际上并不是Adapter模式的一个例子。 协议将更接近,但在Objective C中实现适配器模式的最佳方式是创建一个新对象,其中包含要调整的对象并使用它来为客户端提供服务。

类别是实现适配器模式的另一种方式,但它们有一些限制。 您不能覆盖类别中现有方法的实现,也不能将其他实例变量添加到具有类别的类中。 你所能做的就是添加新的实例方法。 但是,这往往是足够的。

您也可以使用多重继承来实现适用于C ++等语言的Adapter模式,但Objective-C不支持多重继承。

使用我在项目中使用的类别的Adapter的简单示例如下所示:

Interface Builder(IB)包含一个称为“用户定义的运行时属性”的功能,可让您使用键值编码(KVC)在您的自定义界面对象上设置属性。 它允许您指定有限数量的数据类型(整型,浮点型,布尔型,点,矩形,UIColors和其他一些数据类型)。您可以使用用户定义的运行属性来设置视图图层上的边框宽度和角半径,你应该能够使用它来改变图层的边框颜色或背景颜色。 但是,图层颜色被指定为CGColors,UIViews使用UIColors。 由于IB只接受用户定义的运行时属性中的UIColors,因此它不起作用。

为了解决这个问题,我创建了一个名为CALayer + setUIColor的CALayer类。 它有2种方法,setBorderUIColor和setBackgroundUIColor。 这些方法非常简单。 他们以UIColors作为输入,并简单地将UIColor转换为CGColor并设置图层的边框颜色或背景颜色。

你可以在我的github项目KeyframeViewAnimations中看到这个类别的早期版本。


相关问答

更多
  • 它不违反Liskov替换原则,除非你在子类中有某些东西使得它的行为对超类没有意义(违反超类的合约)。 这当然是不完整的代码,但我没有看到任何迹象。 它可能违反单一责任原则 ,但我不确定这是适配器实施中的一个巨大问题。 我通常更喜欢委托方式。 It doesn't violate the Liskov Substitution Principle unless you have something in the subclass that makes it behave in a way that doesn ...
  • 适配器的许多例子是微不足道的或不现实的( Rectangle vs. LegacyRectangle,Ratchet vs. Socket , SquarePeg vs RoundPeg , Duck vs. Turkey )。 更糟糕的是,许多不显示不同适配器的多个适配器 ( 有人引用了Java的Arrays.asList作为适配器模式的示例 )。 使用只有一个类的接口与另一个类进行交互似乎是GoF适配器模式的一个很弱的例子。 这种模式使用继承和多态,所以人们期待一个很好的例子来显示不同适配器的适配器的多 ...
  • 我认为IDbCommand和相关的数据库访问组件遵循适配器模式。 这是因为它们为RDBMS产品提供了非常不同的API的通用接口或包装器。 I would argue that the IDbCommand and related database access components follow the adapter pattern. This is because they provide a common interface, or wrapper, for very disparate APIs i ...
  • 您需要使用其语义来实现Adapter,因此,可能必须修改Adaptee实现,以便通过跟踪先前返回的内容逐个返回数组项。 下面是指示性实现,我没有编译或测试它,所以把它作为它代表的逻辑。 public class MyAdaptee implements MyInt { private MyObj[] buffer = new MyObj[0]; private indexOfLastBufferedItemReturned = 0; @Override public MyObj ...
  • 代表实际上并不是Adapter模式的一个例子。 协议将更接近,但在Objective C中实现适配器模式的最佳方式是创建一个新对象,其中包含要调整的对象并使用它来为客户端提供服务。 类别是实现适配器模式的另一种方式,但它们有一些限制。 您不能覆盖类别中现有方法的实现,也不能将其他实例变量添加到具有类别的类中。 你所能做的就是添加新的实例方法。 但是,这往往是足够的。 您也可以使用多重继承来实现适用于C ++等语言的Adapter模式,但Objective-C不支持多重继承。 使用我在项目中使用的类别的Ada ...
  • 只要老板说罚款那么它应该没问题。 As long as the boss says its fine then it should be fine.
  • .NET中的Runtime Callable Wrapper(RCW)功能更像是Proxy模式的应用程序,因为.NET类镜像了底层COM组件的接口。 来自Sourcemaking的报价: 适配器为其主题提供不同的界面。 代理提供相同的接口。 相关资源: 运行时可调用包装器(RCW) 代理设计模式 适配器设计模式 The Runtime Callable Wrapper (RCW) functionality in .NET is more an application of the Proxy patter ...
  • 不,他们不是。 当您需要在两个相似但不相同的类型之间转换接口时,将使用GoF适配器。 最常见的情况是在两个库之间进行接口时,这两个库之间没有相互编写。 例如,您可以使用返回Map的库,但是您希望将该结果传递到需要JSONObject的网络库中。 您可以使用适配器模式来转换它(这是一个简单的例子,但你明白了)。 像ListView或RecyclerView这样的Android适配器不会这样做。 相反,它从模型中获取数据并将其放入View中。 真正最接近的是MVP演示者。 世界上有许多类似于GoF的类与这些模式 ...
  • 我看到它的方式,你有三个选择: 如果您只需要从B转换为A ,则不需要适配器。 只需将toClassA()方法添加到类B. 如果要映射类A接口以模拟类B接口,请使用适配器,以便在需要A功能时实际仅实例化适配器(并隐式地A )。 如果B向A添加功能,则从A :经典继承或甚至多继承派生B ,如果您需要与我们不知道的C类的接口兼容性。 The way I see it, you have three options: If your only need is conversion from B to A, you ...
  • 从C#3.0设计模式中提取的所有引号,恰好与您的问题相同。 大胆强调指数在我身上。 在双向适配器上: 适配器提供对Adaptee中某些行为的访问(ITarget接口中所需的行为),但Adapter对象不能与Adaptee对象互换。 它们不能在Adaptee对象可以使用的地方使用,因为它们可以处理Adaptee的实现,而不是它的接口。 有时我们需要具有透明ITarget或Adaptee对象的对象 。 如果适配器从两个类继承,则可以轻松实现这一点; 但是,这种多重继承在C#中是不可能的,所以我们必须看看其他解决 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)