Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of Google API Key. Considered children into maps image #5

Merged
merged 1 commit into from May 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions Example/MapExample.js
Expand Up @@ -17,7 +17,8 @@ const mockLocation = {
size: {
width: 300,
height: 550
}
},
key: ''//'AAAAAAAAAA-BBBBBBBBBBBBBBBBB-CCCCCCCCCC'
}


Expand All @@ -30,7 +31,9 @@ class MapExample extends Component {
return (
<View style={styles.content}>
<Text style={styles.title} >Google Static Maps</Text>
<GoogleStaticMap style={styles.map} {...mockLocation} />
<GoogleStaticMap style={styles.map} {...mockLocation} >
<Text>Something here!</Text>
</GoogleStaticMap>
</View>
);
}
Expand Down
15 changes: 10 additions & 5 deletions GoogleStaticMap.js
Expand Up @@ -63,7 +63,7 @@ class GoogleStaticMap extends Component {
*/
static ApiKey = null;

static RootUrl = 'http://maps.googleapis.com/maps/api/staticmap';
static RootUrl = 'https://maps.googleapis.com/maps/api/staticmap';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the https, this doesn't work on IOS
please merge this asap

static ImageFormats = IMAGE_FORMATS;

Expand Down Expand Up @@ -109,7 +109,9 @@ class GoogleStaticMap extends Component {
/**
* Add a marker on the center
*/
hasCenterMarker: React.PropTypes.bool
hasCenterMarker: React.PropTypes.bool,

key: React.PropTypes.string.isRequired,
};

static defaultProps = {
Expand All @@ -124,7 +126,9 @@ class GoogleStaticMap extends Component {
<Image
style={[this.props.style, this.props.size]}
source={{uri: this.staticMapUrl}}
/>
>
{this.props.children}
</Image>
);
}

Expand All @@ -141,7 +145,7 @@ class GoogleStaticMap extends Component {

const {width, height} = size;
const rootUrl = this.constructor.RootUrl;

return `${rootUrl}?center=${latitude},${longitude}&zoom=${zoom}&scale=${scale}&size=${width}x${height}&maptype=${mapType}&format=${format}&${this.markerParams}&${this.apiKeyParam}`;
}

Expand All @@ -157,7 +161,8 @@ class GoogleStaticMap extends Component {
}

get apiKeyParam() {
const apiKey = this.constructor.ApiKey;
const apiKey = this.props.key;

return apiKey ? `key=${apiKey}` : '';
}
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -25,6 +25,7 @@ class MapExample extends Component {
longitude={'34.7748068'}
zoom={13}
size={{ width: 300, height: 550 }}
key={'YOUR-KEY-HERE'}
/>
);
}
Expand All @@ -41,7 +42,7 @@ class MapExample extends Component {
|**`format`**|`string`|'png', 'png32', 'jpg', 'gif', 'jpg-baseline'. use the `GoogleStaticMap.ImageFormats` enum. default is `png`.|
|**`mapType`**|`string`|'roadmap', 'satellite', 'terrain', 'hybrid'. use the `GoogleStaticMap.MapTypes` enum. default is `roadmap`.|
|**`hasCenterMarker`**|`bool`|add a marker on the center. default is `true`.|

|**`key`**|`string`|Google API Key|
and also any `Image.propTypes`.

see: http://facebook.github.io/react-native/docs/image.html#props
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-google-static-map",
"version": "0.1.8",
"version": "0.1.9",
"description": "A wrapper for Google's Static Maps",
"main": "GoogleStaticMap.js",
"repository": {
Expand Down