data-skeptic / home-data-gallery

A place for people to send pull requests for interesting examples they'd like to share
11 stars 8 forks source link

Initialize map to user's local area #16

Open kylepolich opened 8 years ago

kylepolich commented 8 years ago

Right now, code.js assigns a new user to be centered on the continental united states at a large zoom.

It would be preferred if (when possible) the user's actual locale was detected and the zoom and center was picked appropriate to the user for a better experience.

kylepolich commented 8 years ago

Here's the code that would need updating:

  if (state['map']['center_lat'] == undefined) {
    state['map']['center_lat'] = 39.50
  }
  if (state['map']['center_lng'] == undefined) {
    state['map']['center_lng'] = -98.35
  }
  if (state['map']['zoom'] == undefined) {
    state['map']['zoom'] = 4
  }
joytafty commented 8 years ago

One way of doing this:

  1. Get client ip with a React App
  2. Do (low resolution) ipgeo lookup (state, city, county level should be good enough?) using free APIs/libraries (listed below). Fetch latitude, longitude from the center of that geo.