-
Notifications
You must be signed in to change notification settings - Fork 939
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
Geocoder #324
Comments
This project uses His code handles the UI and the API stuff all together, so it's a bit hard to grok.here's my simplified adaptation below (it combines the general flow is:
|
@thiagoterleski what @brandonmp did seems okay. Also, 6.0.0 is released on npm beta tag now. We also have a new demo page. Feel free to try it: |
Is there any chance we can add this geocoder in react-google-maps? @tomchentw |
You're free to submit a pull request anytime! |
As I can tell, to use Geocode you don't need it to be a React Compnenent. You can simply use it in the react lifecycle callbacks |
Would you mind giving a short hint how to use it in the react lifecycle callbacks? I'm struggling with the basics here, I think, and would highly appreciate help. Thanks for the good work! |
@AntoniusGolly You can find Geocode object in
|
@slivniy Thanks for the reply. This works (supposingly) only if I had the google maps library sourced manually with Alternatively, if use a stateless functional component (SFC) I can actually use
and instantiate it with
However, In order to use the SFC I would need to do the geocoder stuff before the mounting of |
Hmm, still doesn't work without sourcing google maps api manually. The error remains "Cannot read property 'maps' of undefined. Do you suggest to put the |
@AntoniusGolly I'm using Geocoder not right after component mounted, but on user click on some input - and in that time usually If you need it really in
That's checked :) That's simplest way. Though I prefer to declare MyMapComponent variable in |
Thank you, @slivniy ! |
I am trying to change the state value inside the componentDidMount().But it only accepts props values |
@pranabunni If you change it to a Component or PureComponent you'll then have access to state. For example: import React, { Component } from 'react'
import { withScriptjs, withGoogleMap, GoogleMap } from 'react-google-maps'
import { compose, withProps } from 'recompose'
class MapComponent extends Component {
componentDidMount() {
let geocoder = new window.google.maps.Geocoder();
geocoder.geocode( { 'address': 'Bakerstreet, 2'}, function(results, status) {
if (status == 'OK') {
this.setState({
lat: results[0].geometry.location.lat(),
lng: results[0].geometry.location.lng()
})
} else {
console.log('Geocode was not successful for the following reason:', status);
}
})
}
render() {
const { lat, lng } = this.state
return lat && lng ? <GoogleMap
defaultZoom={7}
defaultCenter={{ lat, lng }}
>
</GoogleMap> : <div>Loading...</div>
}
}
export default compose(
withProps({
googleMapURL: ('https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places&key=' + API_KEY),
loadingElement: (<div style={{ height: '100%' }} />),
containerElement: (<div style={{ height: '400px' }} />),
mapElement: (<div style={{ height: '100%' }} />)
}),
withScriptjs,
withGoogleMap)(MapComponent) |
How can i use the
new google.maps.Geocoder()
library?, i'm using the ScriptjsLoader to load map lib, and i need to search the address from my point.The text was updated successfully, but these errors were encountered: