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.

How can i center map to again the default position lat and lng dynamcaly

See original GitHub issue

I have this code


import React from "react";
import ReactDOM from "react-dom";
import { compose, withProps } from "recompose";
import {
  withScriptjs,
  withGoogleMap,
  GoogleMap,
  Marker,
  Circle
} from "react-google-maps";
import config from 'config';

const GoogleMaps = compose(
  withProps({
    /**
     * Note: create and replace your own key in the Google console.
     * https://console.developers.google.com/apis/dashboard
     * The key "AIzaSyBkNaAGLEVq0YLQMi-PYEMabFeREadYe1Q" can be ONLY used in this sandbox (no forked).
     */
    googleMapURL:
      "https://maps.googleapis.com/maps/api/js?key=" + config.googlemaps + "v=3.exp&libraries=geometry,drawing,places",
    loadingElement: <div style={{ height: `100%` }} />,
    containerElement: <div style={{ height: `300px` }} />,
    mapElement: <div style={{ height: `100%` }} />
  }),
  withScriptjs,
  withGoogleMap
)(props => (
  <GoogleMap defaultZoom={8} defaultCenter={new google.maps.LatLng(props.lat,  props.lng)}>
    {props.isMarkerShown && (
      <Marker position={{ lat: props.lat, lng: props.lng }} />
    )}
     {props.isCircle && (
      <Circle radius={10000}  visible={true} center={{ lat: props.lat, lng: props.lng }}/>
     )}
    </GoogleMap>
));

export { GoogleMaps };

after i have change the lat and lng props the element map stays on first position how to center it to the marker ?

Many thanks Carlos Vieira

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ShintaroNipponcommented, Mar 19, 2018

Solution found…

center={new google.maps.LatLng(props.lat, props.lng)}

thanks Carlos Vieira

0reactions
vmobeedevelopercommented, Dec 21, 2020

@ShintaroNippon 100% worked this solution (If Radius not update) <Circle center={{ lat: item.lat, lng: item.lng }} radius={2000} visible={true} options={{ strokeColor: “#ff0000” }} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google map API dynamic lat/lng initial center not showing ...
I get item lat/lng and set them to state, to use in maps. When I step through everything it is the correct lat:32.735962/lng:-96.275256...
Read more >
Getting Lat/Lng from a Click Event | Maps JavaScript API
To navigate, press the arrow keys. Click the map to get Lat/Lng! zoom: 4, center: myLatlng,
Read more >
Dynamic Google Maps
With the Dynamic Google Maps widget you can create an interactive map ... Latitude and Longitude ... The position on the map is...
Read more >
Google Maps API - Map options, properties, controls
center. LatLng. Determines the initial center of the map. Required. Constructor : LatLng(lat:number, lng:number, noWrap?:boolean). Creates a ...
Read more >
The Map component - Google Web Designer Help
Enter the Latitude and Longitude properties to set the default center point of the map. (Learn how to find the coordinates of a...
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