Skip to content
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

Switch Geocoding API from Google to Mapbox #136

Closed
jimthoburn opened this issue Feb 11, 2017 · 5 comments
Closed

Switch Geocoding API from Google to Mapbox #136

jimthoburn opened this issue Feb 11, 2017 · 5 comments
Labels
idea Suggestions, ideas that could be discussed and reviewed with the team Missing: Feature The feature tag is missing for this issue Missing: Role The role is missing from this issue Missing: Size The effort estimate for this issue is missing

Comments

@jimthoburn
Copy link
Member

https://www.mapbox.com/help/define-geocoding/

@jgravois
Copy link

jgravois commented Mar 10, 2017

do you have your heart set on using Mapbox for geocoding? Esri's is 💯 , supports suggestions and POI search and allows up to 1 million unauthenticated requests a month.

we already wrote a plugin for Leaflet, but i've been looking for an excuse to make something that has no map dependencies whatsoever too...

@jimthoburn
Copy link
Member Author

jimthoburn commented Mar 14, 2017

Thanks for the tip, John! I‘ll have to check out Esri. It sounds awesome. : )

@georgefpope
Copy link

georgefpope commented May 31, 2017

Comparing the two APIs, we currently have:

	var geocoder = new google.maps.Geocoder();  
	geocoder.geocode({'address': address}, function(results, status) { ... }

The Mapbox call would look like the following:

            var client = new MapboxClient('YOUR_ACCESS_TOKEN');
            client.geocodeForward('Chester, NJ', function(err, data, res) {
                    // data is the geocoding result as parsed JSON
                    // res is the http response, including: status, headers and entity properties
             });

Thus it would appear to be a relatively straightforward substitution.

@jimthoburn
Copy link
Member Author

Awesome, George!

FOLA’s access token for Mapbox is available as a global variable called MAP_ACCESS_TOKEN.

var client = new MapboxClient(MAP_ACCESS_TOKEN);

After the switch, we can remove the Google Maps <script> element from these two files, which will save bandwidth and processing time…

https://github.com/foodoasisla/site/blob/master/_layouts/location-details.html
https://github.com/foodoasisla/site/blob/master/_layouts/location-list.html

<script src="https://maps.googleapis.com/maps/api/js?…"></script>

@jimthoburn
Copy link
Member Author

While we were working on the Add a location page, @LearningNerd found a way to do geolocation using the Mapbox API, without loading any additional third-party JavaScript!

You can see some example code here…
https://github.com/foodoasisla/site/blob/master/assets/js/github-backend.js

It looks like this…

var addressForGeocoding = '220 S Spring Street, Los Angeles';

var MAP_ACCESS_TOKEN = 'pk.eyJ1IjoiZm9vZG9hc2lzbGEiLCJhIjoiY2l0ZjdudnN4MDhpYzJvbXlpb3IyOHg2OSJ9.POBdqXF5EIsGwfEzCm8Y3Q';

var MAPBOX_URL = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURIComponent(addressForGeocoding) + '.json?limit=1&access_token=' + MAP_ACCESS_TOKEN;

get(MAPBOX_URL)
.then(JSON.parse).then(function (mapboxResponse){

  longitude = mapboxResponse.features[0].center[0];
  latitude  = mapboxResponse.features[0].center[1];

}).catch(logAndDisplayError);

@chombus chombus transferred this issue from hackforla/food-oasis-la Nov 18, 2019
@chombus chombus added the idea Suggestions, ideas that could be discussed and reviewed with the team label Nov 18, 2019
@bbovenzi bbovenzi closed this as completed Nov 4, 2020
@ExperimentsInHonesty ExperimentsInHonesty added Missing: Role The role is missing from this issue Missing: Size The effort estimate for this issue is missing Missing: Feature The feature tag is missing for this issue labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Suggestions, ideas that could be discussed and reviewed with the team Missing: Feature The feature tag is missing for this issue Missing: Role The role is missing from this issue Missing: Size The effort estimate for this issue is missing
Projects
Archived in project
Development

No branches or pull requests

7 participants