etodanik / ion-google-place

Ionic directive for a location dropdown that utilizes google maps
MIT License
251 stars 201 forks source link

How to get only streets? #41

Open jklas opened 9 years ago

jklas commented 9 years ago

I'm developing an application where I'm only interested in getting streets, not cities or provinces, is there a specific or recommended way to filter those?

In the meanwhile I've ended up hacking ion-google-place.js, namely the geocoder.geocode line:

geocoder.geocode(req, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        scope.$apply(function() {
            var filteredResults = [];
            for(i in results) {
                var valid = false;
                for(j in results[i].address_components) {
                    for(k in results[i].address_components) {
                        var type = results[i].address_components[j].types[k];
                        if( type === "route" || type === "establishment"
                            || type === "point_of_interest" ) valid = true;
                    }
                }
                if(valid) filteredResults.push(results[i]);
            }
        scope.locations = filteredResults;
    });
} else {
    // @TODO: Figure out what to do when the geocoding fails
    }
});

Thanks!