admin管理员组文章数量:1357225
We tried unsuccessfully to have google maps embedded in our app. The autoplete field has not been a problem but we tried to insert the map the same way and something went wrong.
We use react 0.12 and we create a ponent for the autoplete field.
var Geoplete = React.createClass({
ponentDidMount: function() {
var inputOptions = {ponentRestrictions: {country: 'it'}};
new google.maps.places.Autoplete(
document.getElementById('searchTextField'),
inputOptions);
},
buttonClick: function() {
alert(this.refs.searchField.getDOMNode().value);
},
// <div id="map-canvas"></div>
render: function() {
return (
<div>
<label htmlFor="searchTextField">
Please Insert an address:
</label>
<br/>
<input ref='searchField' id="searchTextField" type="text" size="50"/>
<br/>
<button onClick={this.buttonClick}>Submit</button>
<br />
</div>
);
}
});
module.exports = Geoplete;
We tried unsuccessfully to have google maps embedded in our app. The autoplete field has not been a problem but we tried to insert the map the same way and something went wrong.
We use react 0.12 and we create a ponent for the autoplete field.
var Geoplete = React.createClass({
ponentDidMount: function() {
var inputOptions = {ponentRestrictions: {country: 'it'}};
new google.maps.places.Autoplete(
document.getElementById('searchTextField'),
inputOptions);
},
buttonClick: function() {
alert(this.refs.searchField.getDOMNode().value);
},
// <div id="map-canvas"></div>
render: function() {
return (
<div>
<label htmlFor="searchTextField">
Please Insert an address:
</label>
<br/>
<input ref='searchField' id="searchTextField" type="text" size="50"/>
<br/>
<button onClick={this.buttonClick}>Submit</button>
<br />
</div>
);
}
});
module.exports = Geoplete;
Share
Improve this question
edited Apr 21, 2015 at 22:37
tbodt
17k7 gold badges61 silver badges86 bronze badges
asked Apr 9, 2015 at 7:27
LucaGLucaG
611 silver badge3 bronze badges
2 Answers
Reset to default 6try with this code:
ponent:
var GoogleMap = React.createClass({
getDefaultProps: function () {
return {
initialZoom: 6,
mapCenterLat: 53.5333,
mapCenterLng: -113.4073126
};
},
ponentDidMount: function (rootNode) {
var mapOptions = {
center: this.mapCenterLatLng(),
zoom: this.props.initialZoom
},
map = new google.maps.Map(this.getDOMNode(), mapOptions);
var marker = new google.maps.Marker({position: this.mapCenterLatLng(), title: 'Hi', map: map});
this.setState({map: map});
},
mapCenterLatLng: function () {
var props = this.props;
return new google.maps.LatLng(props.mapCenterLat, props.mapCenterLng);
},
render: function () {
return (
<div className='map-gic'></div>
);
}
});
module.exports = GoogleMap;
then to show it in a page:
<GoogleMap mlat="55.0000" mlong="-113.0000"/>
css:
.map-gic {
height: 300px;
width: 100%;
}
this works for me
I found easier implementations.
Check this one: https://github./BrodaNoel/devseverywhere/blob/master/src/pages/AnalyticsPage/AnalyticsPage.jsx#L227
It's using the google-map-react
npm package.
本文标签: javascriptGoogle maps in reactStack Overflow
版权声明:本文标题:javascript - Google maps in react - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744077072a2586943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论