message: Fix: Geolocate with API by default
diff: @@ -151,9 +151,31 @@ class MapComponent extends React.Component<Props, State> {
  }
  private centerMap = () => {
  + let location: {
  + lat: number;
  + lng: number;
  + };
  + fetch('https://get.geojs.io/v1/ip/geo.json')
  + .then(response => response.json())
  + .then(data => {
  + // If the API returns a geolocation
  + if (data.longitude && data.latitude) {
  + location = {
  + lat: parseFloat(data.latitude),
  + lng: parseFloat(data.longitude),
  + };
  + const { map } = mapState();
  + if (!map) {
  + return;
  + }
  + map.map.setCenter(location);
  + map.map.setZoom(8);
  + mapState().updateResultsOnNextBoundsChange = true;
  + } else {
  + // Call the browser's geolocation API (will prompt the first time)
  navigator.geolocation.getCurrentPosition(
  position => {
  - const pos = {
  + location = {
  lat: position.coords.latitude,
  lng: position.coords.longitude,
  };
  @@ -161,12 +183,13 @@ class MapComponent extends React.Component<Props, State> {
  if (!map) {
  return;
  }
  - map.map.setCenter(pos);
  + map.map.setCenter(location);
  map.map.setZoom(8);
  mapState().updateResultsOnNextBoundsChange = true;
  },
  () => {
  - const positionOfIndia = {
  + // Position over India if no other option works
  + location = {
  lat: 21.7679,
  lng: 78.8718,
  };
  @@ -174,11 +197,13 @@ class MapComponent extends React.Component<Props, State> {
  if (!map) {
  return;
  }
  - map.map.setCenter(positionOfIndia);
  + map.map.setCenter(location);
  map.map.setZoom(4);
  mapState().updateResultsOnNextBoundsChange = true;
  },
  );
  + }
  + });
  };
  private updateMarkersVisibilityUsingFilter = (filter: Filter) => {
  