我将使用osmdroid开始使用Open Street Maps。在github wiki上找到的初学者教程说,您必须设置用户代理以防止被osm服务器禁止。评论并没有超出关于如何做到这一点的提示。因此,运行代码的结果是我在结果映射中看不到任何内容。只有地图画布和缩放控件,但没有像地理点或其他东西 我的活动代码如下(使用osmdroid库的5.6.5版本):
public class MapActivity extends AppCompatActivity {
MapView map = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
Context ctx = getApplicationContext();
//important! set your user agent to prevent getting banned from the osm servers
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(9);
GeoPoint startPoint = new GeoPoint(48.8583, 2.2944);
mapController.setCenter(startPoint);
}
public void onResume() {
super.onResume();
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
// map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
}
public void onPause(){
super.onPause();
// map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
}
答案 0 :(得分:4)
Configuration.getInstance().load
实际上会为您设置它。您可以通过Configuration.getInstance().setUserAgent
我会更新维基以反映
基本上,它从清单中获取apk的包名并使用它(默认情况下)