【发布时间】:2016-04-29 07:04:17
【问题描述】:
我的目标是在 React Native 中显示谷歌地图。我已经看到使用带有 UIMapView 或 MapBox 地图的 Google Maps SDK 的示例,但这不是我想要的。
我目前没有错误。这是我的代码:
index.ios.js
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View
} from 'react-native';
import GoogleMaps from './ios/GoogleMaps.js';
class RCTGoogleMaps extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.container}>
<GoogleMaps style={styles.map}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
map: {
height: 500,
width: 300,
marginLeft: 50
}
});
AppRegistry.registerComponent('RCTGoogleMaps', () => RCTGoogleMaps);
ios/GoogleMaps.js
var {requireNativeComponent} = require('react-native');
module.exports = requireNativeComponent('RCTGoogleMapViewManager', null);
ios/RCTGoogleMapViewManager.h
#ifndef RCTGoogleMapViewManager_h
#define RCTGoogleMapViewManager_h
#import <Foundation/Foundation.h>
#import "RCTViewManager.h"
#import <UIKit/UIKit.h>
@interface RCTGoogleMapViewManager : RCTViewManager<UITextViewDelegate>
@end
#endif /* RCTGoogleMapViewManager_h */
ios/GoogleMapViewManager.m
#import <Foundation/Foundation.h>
#import "RCTGoogleMapViewManager.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "UIView+React.h"
@import GoogleMaps;
@implementation RCTGoogleMapViewManager
RCT_EXPORT_MODULE()
- (UIView *)view {
GMSMapView *mapView_;
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
UIView *newView_ = mapView_;
//self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
return newView_;
}
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
@end
组件周围有一个红色边框,但内部没有任何显示。我是 React Native 的新手,也是 StackOverflow 的新手。不幸的是,在我获得更多声誉之前,他们不会让我上传屏幕截图。
我怀疑有一条线路已关闭,但不知道将其更改为什么。 RCTGoogleMapViewManager.h 中的第 8 行显示“@interface RCTGoogleMapViewManager : RCTViewManager”。我已将 UITextViewDelegates 用于其他自定义组件,但此地图不是 TextView。可能是这样,但我不知道。
任何帮助都将不胜感激。
【问题讨论】:
标签: ios google-maps google-maps-api-3 react-native