Jef*_*iks 11 google-maps google-maps-api-3 ios react-native
我的目标是在React Native中显示Google Map.我见过将Google Maps SDK与UIMapView或MapBox地图一起使用的示例,但这不是我要找的.
我目前没有错误.这是我的代码:
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);
Run Code Online (Sandbox Code Playgroud)
IOS/GoogleMaps.js
var {requireNativeComponent} = require('react-native');
module.exports = requireNativeComponent('RCTGoogleMapViewManager', null);
Run Code Online (Sandbox Code Playgroud)
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 */
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
组件周围有红色边框,但内部没有任何显示.我是React Native的新手,也是StackOverflow的新手.不幸的是,在我获得更多声誉之前,他们不会让我上传截图.
有一条线我怀疑要关闭,但不知道要改变它.RCTGoogleMapViewManager.h中的第8行说"@interface RCTGoogleMapViewManager:RCTViewManager".我已将UITextViewDelegates用于其他自定义组件,但此映射不是TextView.可能是这样,但我不知道.
任何帮助都将不胜感激.
| 归档时间: |
|
| 查看次数: |
6671 次 |
| 最近记录: |