我正在使用RubyMotion和MapBox创建一个应用程序。我想要一个带标记的离线地图。我可以看到地图而不是标记。这是我的代码:
class MapScreen < PM::Screen
def on_load
RMConfiguration.configuration.setAccessToken("...")
self.view.addSubview(map_view)
annotation = RMPointAnnotation.alloc.initWithMapView(map_view, coordinate: map_view.centerCoordinate, andTitle: 'Hello')
map_view.addAnnotation(annotation)
end
def map_view
return @map_view if @map_view
source = RMMBTilesSource.alloc.initWithTileSetResource('control-room-0.2.0',
ofType:'mbtiles')
@map_view ||= RMMapView.alloc.initWithFrame(self.view.bounds, andTilesource:source).tap do |map|
map.zoom = 2
map.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
map.setCenterCoordinate(CLLocationCoordinate2D.new(0, 0))
map.showsUserLocation = true
end
end
end
有解决方案吗?
答案 0 :(得分:2)
该代码应该有效:
class MapScreen < PM::Screen
def on_load
RMConfiguration.configuration.setAccessToken("...")
self.view.addSubview(map_view)
annotation = RMAnnotation.alloc.initWithMapView(map_view, coordinate: map_view.centerCoordinate, andTitle: 'Hello')
map_view.addAnnotation(annotation)
end
def map_view
return @map_view if @map_view
source = RMMBTilesSource.alloc.initWithTileSetResource('control-room-0.2.0', ofType:'mbtiles')
@map_view ||= RMMapView.alloc.initWithFrame(self.view.bounds, andTilesource:source).tap do |map|
map.zoom = 4
map.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
map.setCenterCoordinate(CLLocationCoordinate2D.new(0, 0))
map.showsUserLocation = true
map.delegate = self
end
end
def mapView(map_view, layerForAnnotation:annotation)
image = UIImage.imageNamed('list.png')
RMMarker.alloc.initWithUIImage(image)
end
end