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

Replace Mapzen with Google Maps #18

Open
pral2a opened this issue Mar 19, 2018 · 1 comment
Open

Replace Mapzen with Google Maps #18

pral2a opened this issue Mar 19, 2018 · 1 comment

Comments

@pral2a
Copy link
Member

pral2a commented Mar 19, 2018

Mapzen is being deprecated so we'll need to move to the Google Maps API:

function querySearch(query) {
return $q.all([getMetadata(query), getPlacesMapzen(query)])
.then(function(data) {
if(data.length === 0) {
//enable scrolling on body if there is no dropdown
angular.element(document.body).css('overflow', 'auto');
return data;
}
//disable scrolling on body if dropdown is present
angular.element(document.body).css('overflow', 'hidden');
return joinSearches(data);
});
}
function getMetadata(keywords){
keywords = keywords.replace(' ', '+');
return asset.getMetadata(keywords);
}
function getPlacesMapzen(location){
location = location.replace(' ', '+');
return $http.get('https://search.mapzen.com/v1/autocomplete?api_key=search-h8Qe8fY&text='+ location);
}
function filterPlaces(places){
if (!places || !places.data || places.data.features.length === 0){ return [];}
places = places.data.features.slice(0, 3); //just first 5 results
return _.map(places, getMapzenPlaceReadyForModel);
}
function filterEntities(assets){
if (!assets || assets.length === 0){ return [];}
return _.map(assets, getMetadataReadyForModel);
}
function getMapzenPlaceReadyForModel(place){
var searchResult = {
type: 'location',
name: place.properties.label,
longitude: place.geometry.coordinates[0],
latitude: place.geometry.coordinates[1]
};
return new SearchResultLocation(searchResult);
}
function getMetadataReadyForModel(asset){
return new SearchResult(asset);
}
function joinSearches(data){
var e = filterEntities(data[0]);
var p = filterPlaces(data[1]);
return p.concat(e);
}

@viktorsmari
Copy link
Contributor

viktorsmari commented May 8, 2018

URL to the API works fine standalone:
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyCMUbKxhE3BWLRClSC6lxcWHMgXr7BB-J4&input=pujades

But we are getting the CORS error

Maybe we need to load a Google Places library, and use their built in functions?

Documentation:
https://developers.google.com/maps/documentation/javascript/places-autocomplete

@viktorsmari viktorsmari removed their assignment Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants