谷歌地图(iOS)
我的目标是在React Native中显示谷歌地图。我看到过一些例子,它们将GoogleMapsSDK与UIMapView或MapBox地图结合使用,但这不是我想要的 我目前没有错误。这是我的密码: index.ios.js谷歌地图(iOS),ios,google-maps,google-maps-api-3,react-native,Ios,Google Maps,Google Maps Api 3,React Native,我的目标是在React Native中显示谷歌地图。我看到过一些例子,它们将GoogleMapsSDK与UIMapView或MapBox地图结合使用,但这不是我想要的 我目前没有错误。这是我的密码: index.ios.js 'use strict'; import React, { AppRegistry, Component, StyleSheet, Text, View } from 'react-native'; import GoogleMaps
'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/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 */
#如果NDEF RCTGoogleMapViewManager
#定义RCTGoogleMapViewManager\u h
#进口
#导入“RCTViewManager.h”
#进口
@接口RCTGoogleMapViewManager:RCTViewManager
@结束
#endif/*RCTGoogleMapViewManager\u 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
#导入
#导入“RCTGoogleMapViewManager.h”
#导入“RCTBridge.h”
#导入“RCTEventDispatcher.h”
#导入“UIView+React.h”
@导入谷歌地图;
@实现RCTGoogleMapViewManager
RCT_导出_模块()
-(UIView*)视图{
GMSMapView*地图视图;
//创建一个GMSCameraPosition,告诉地图显示
//缩放级别6时的坐标-33.86151.20。
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机拍摄时的纬度:-33.86
经度:151.20
缩放:6];
地图视图=[GMSMapView地图WithFrame:CGRectZero相机:相机];
mapView_u2;.myLocationEnabled=是;
UIView*新视图=地图视图;
//self.view=mapView;
//在地图的中心创建一个标记。
GMSMarker*标记=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake(-33.86151.20);
marker.title=@“悉尼”;
marker.snippet=@“澳大利亚”;
marker.map=mapView;
返回newView;
}
RCT\u导出\u视图\u属性(文本,NSString)
@结束
组件周围有一个红色边框,但内部没有显示任何内容。我是个新来的本地人,对StackOverflow也不熟悉。不幸的是,他们不会让我上传截图,直到我有更多的声誉
我怀疑有一条线路断开了,但不知道该换成什么。RCTGoogleMapViewManager.h中的第8行说,“@interface RCTGoogleMapViewManager:RCTViewManager”。我已将UITextViewDelegates用于其他自定义组件,但此映射不是TextView。可能是这样,但我不知道
任何帮助都将不胜感激。您退房了吗?它看起来相当初步,但对您仍然非常有用。如果组件周围有红色边框,但内部没有显示任何内容,则表示您没有正确链接库 请在此处查看文档:
#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