问题描述
确定。你可能会认为这将是比较简单的,但是没了。
Ok. You'd think this would be relatively simple, but nope.
我使用开放街道地图在我的网站,因为数据是免费使用,修改和更新 - 我的项目遵循这个咒语,并沿着Google的API使用限制/保存数据的限制,谷歌地图根本不适合我..至少在网络上。
I am using Open street maps on my website, as the data is free to use, edit, and update - my project follows this mantra, and alongside googles API usage restrictions/saving data restrictions, google maps simply was not suitable for me.. at least on the web.
鉴于此我想我会跟风与我的Android应用程序,所以我设置osmdroid利用开放街道地图数据。
Given this I thought i'd follow suit with my android app, and so I setup osmdroid utilizing open street maps data.
我可以在我的活动一个很好的地图。我也跟着教程,它似乎工作至少这样我可以有一个片段tabhost / viewpager内的地图视图。我真正想要的不过(对于平板电脑),是机构在左侧的片段的列表,右边的地图片段表示在这些场所的。
I can have a nice map in my activity.. I also followed a tutorial, and it seemed to work at least such that I can have a map view in a fragment within a tabhost/viewpager. What i really want however (for tablets), is a list of establishments in a fragment on the left, and a map fragment on the right showing where these establishments are.
够简单了,我会想到,但时间和研究时间建议,除非你使用一些复杂的code和一些去precated方法,这是不可能的。
Simple enough i would have thought, but hours and hours of research suggest this is not possible unless you use some complex code and some deprecated methods..
所以..片段(包含地图视图)负载,并在tabhost完美运行..我可以从我的活动等片段中访问方法..还没有什么,只是简单地有两个片段并列。
So.. the fragment (containing a map view) loads and runs perfectly in a tabhost.. i can access methods within the fragment from my activity etc.. yet nothing to just simply have two fragments side by side.
现在..我知道谷歌刚刚推出了自己的API第2版。我安装了它,有一出戏......不是真的知道osmdroid是如何工作的,我以为我可以更新,所以我已经MapFragment,而不是SherlockFragment(我用的ABS)..这然后就吐了错误的logcat要求API密钥等。并鉴于我不想使用谷歌地图数据,我认为我已经错了。
Now.. I know google have just come out with their API v2.. I installed it and had a play.. not really knowing how osmdroid works, I thought i could update so I have MapFragment instead of SherlockFragment (I use ABS).. this then just threw up logcat errors asking for API keys etc.. and given that I dont want to use google map data, I assumed that I had gone wrong.
所以..任何人都可以提出建议我如何能得到一个列表的片段,并使用任何可用市场上的地图片段并排,但是preferably使用开源地图数据,使得他们没有使用限制。
So.. could anyone advise on how I can get a list fragment, and a map fragment side by side using anything that is available on the market, but preferably utilizing Open source map data such that their are no usage restrictions.
我敢肯定的总体概述什么是可用的,以及它是如何工作将是用户的负载pciated非常AP $ P $ ..因此,如果任何人都可以告知这将是惊人的!
I'm sure an overall overview of "what is available, and how it works" would be very much appreciated by loads of users.. so if anyone could advise it would be amazing !
推荐答案
新的谷歌地图API出来之前,我被迫使用OSMDroid我的目的。然而,有通过源多次挖掘弄清楚它为什么做它是(经常不正确地)以后,我要死了新库。
Before the new Google Maps API came out, I was forced into using OSMDroid for my purposes. However, after having to dig through the source several times to figure out why it was doing what it was (often incorrectly), I was dying for a new library.
幸运的是,新的谷歌地图API符合该法案。您可以使用谷歌地图API V2在你的应用程序,并从来没有使用谷歌的底图,但肯定的,不幸的是你必须先获得API密钥。
Fortunately, the new Google Maps API fits the bill. You can use the Google Maps API v2 in your application and never have to use Google's basemaps, but yes, unfortunately you must get an API key first.
我假设你想使用OpenStreetMap的为在线地图来源,因此code以下将实现这一量身定做。
I am assuming you want to use OpenStreetMap as an online map source, so the code below will be tailored towards that.
GoogleMap map = <get-map-instance>;
map.setMapType(GoogleMap.MAP_TYPE_NONE);
TileOverlayOptions options = new TileOverlayOptions();
options.tileProvider(new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int z) {
try {
String f = "http://tile.openstreetmap.org/%d/%d/%d.png";
return new URL(String.format(f, z, x, y));
}
catch (MalformedURLException e) {
return null;
}
}
});
map.addTileOverlay(options);
您可以找到这个code在我的谷歌地图API V2的附加组件库here.
You can find a more formalized version of this code in my Google Maps API v2 add-ons library here.
另外,如果你的目标pre-片段的Android版本,这一点我相信你是根据你使用的ABS,而不是使用MapFragment,请确保您使用SupportMapFragment。
Also, if you are targeting pre-Fragment Android versions, which I believe you are based on you using ABS, instead of using MapFragment, make sure you use SupportMapFragment.
这篇关于osmdroid,地图API v2和片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!