question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant set center of the map.

See original GitHub issue

I am trying to set the center of the map but to no success. What am i doing wrong? The map marker is positioned to geolocation but center is not changing.

classSimpleMapPage extends Component {
 mixins: [PureRenderMixin];
 constructor () {
     super();
     this.state = {
         center: {
             lat: 23.938043,
             lng: 73.337157
         },
         zoom: 14
     };
 }

 componentDidMount() {
     navigator.geolocation.getCurrentPosition(
          (position) => {
              this.setState({
                      center: {
                          lat: position.coords.latitude,
                          lng: position.coords.longitude
                      }
                  }
              );
              // var center = this.state.center;
              // center.lat = position.coords.latitude;
              // center.lng = position.coords.longitude;
              // this.setState({center: center});
          },
          (error) => { console.log(error.message),
          {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
      );
 }

 render() {
     return (
         <GoogleMap center={this.state.center} zoom={this.state.zoom} >
             <MapMarker lat={this.state.center.lat} lng={this.state.center.lng} text={'Me'}/>
         </GoogleMap>
     );
 }
};`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
istarkovcommented, Nov 20, 2016
0reactions
lock[bot]commented, Dec 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How come my setCenter doesn't work? - Stack Overflow
But map.setCenter won't work. I thought it was because I wasn't calling LatLng parameters correctly, but discovered it won't work even if I ......
Read more >
Map.setCenter - Earth Engine - Google Developers
Centers the map view at a given coordinates with the given zoom level. ... Set the position and optional zoom level of the...
Read more >
Recentering map not working - Google Groups
"map.setCenter" doesn't work. The map reloads but stays at the old center (you can see it both on the map ... any different...
Read more >
Fix a missing address or wrong pin location - Google Maps Help
You can publicly add or edit addresses in Maps. Add mailing addresses, fix ... Move the map to the center of the building....
Read more >
Configure the map—ArcGIS Field Maps | Documentation
Map areas, sharing settings, and the Hide in Field Maps mobile setting are not ... If you add the same layer to your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found