My goal is to display a Google Map in React Native. I have seen examples that use the Google Maps SDK with an UIMapView or a MapBox map, but that is not what I am looking for.
I currently have no errors. Here is my code:
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
There is a red border around the component, but nothing displays inside. I am new to React Native and new to StackOverflow. Unfortunately, they will not let me upload a screenshot until I have more reputation.
There is one line I suspect to be off, but have no idea what to change it to. Line #8 in RCTGoogleMapViewManager.h says, "@interface RCTGoogleMapViewManager : RCTViewManager". I have used UITextViewDelegates for other custom components, but this map is not a TextView. That might be it, but I have no clue.
Any help at all would be appreciated.
If there is a red border around the component but nothing displays inside, that means you have no correctly linked a library.
Check out the docs here: http://facebook.github.io/react-native/releases/0.25/docs/linking-libraries-ios.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With