We are adding a search by address for users to filter facilities near them (right now we just have the basic zip search).
I'm still getting familiar with hubl and the google maps API and need to capture the geocode results as a param. This does not work because the scope of the results doesn't extend to the hubl. How can I get the returned info in there?
I can help, but I think I need to understand your code a little better. How are you currently getting the lat and long? You said that the scope of the results doesn't extend to HubL. Where are the results currently? Is it coming just from the query string?
It's the first time I've worked with the geocoding api, so I set it up on this test page to recenter the map and it has it's own submit button.
As the interim step, I've been trying to capture the values when the results object is returned. But all I get is ?lat=&lon= . Here's the code:
<script>
var geocoder;
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: {lat: 42.3853, lng: -71.8368}
});
{% for row in hubdb_table_rows(table_id, filter_params) %}
var marker_{{ row.hs_id }} = new google.maps.Marker({
map: map,
position: {lat: {{ row.location.lat }}, lng: {{ row.location.lon }} },
icon: { scaledSize: {width: 20, height:20}, url: "https://cdn2.hubspot.net/hubfs/4764394/01012019_ARC_icon_svgs/ARC_map_150px_150px_navy_02.png" },
title: "{{ row.organization }}",
});
marker_{{ row.hs_id }}.addListener('click', function() {
new google.maps.InfoWindow({
content: "<div> {{ row.organization }} </div>"
}).open(map, marker_{{ row.hs_id }});
});
{% endfor %}
geocoder = new google.maps.Geocoder();
document.getElementById('address-submit').addEventListener('click', function() {
codeAddress(geocoder, map);
});
function codeAddress(geocoder, resultsMap) {
var address = document.getElementById('address').value;
geocoder.geocode( {'address' : address}, function(results, status) {
if (status == 'OK') {
resultsMap.setCenter(results[0].geometry.location);
{% set lat_param = lat_param ~ "&latitude=" + results[0].geometry.location.lat|urlencode %}
{% set lon_param = lon_param ~ "&longitude=" + results[0].geometry.location.lat|urlencode %}
var marker_origin = new google.maps.Marker({
map: resultsMap,
title: "You are here.",
icon: { scaledSize: {width:25, height:25}, url: "https://cdn2.hubspot.net/hubfs/4764394/01012019_ARC_icon_svgs/ARC_map_150px_150px_green_02.png"},
position: results[0].geometry.location,
zoom: 14,
});
} else {
alert('Geocode was not successful for the following reason: ' + status)
}
});
}
}
</script>
I figured once I was able to do that, then I could rewrite to the full feature which should use one submit button, so people could filter on the additional options too, and then the return would recenter the map on their address and sort the facility cards by closest first.
Does this help you help me? What else can I provide? Should I add you to the project so you can look at my (super-messy, unrefactored) module?