Robert Saylor
asked on
google maps API
I am building a list to map and almost have it working.
I have a list of properties on one side and the map on the other. When I click on the address I want it to pan on the map.
I was reviewing this site:
https://stackoverflow.com/questions/14306098/google-maps-api-pan-to-markers-from-a-list
In my maps js I am using:
$("#contacts").on("click", "#{{p.Matrix_Unique_ID}}", function() {
var laLatLng = new google.maps.LatLng({{p.Lat itude}}, {{p.Longitude}});
map.panTo(laLatLng);
map.setZoom(5);
});
And on my list I am using:
<a href="javascript:void(0)" id="{{p.Matrix_Unique_ID}} " data-city="{{p.Address}}"> Map</a>
How do I register the click? That is the part I am not sure. If I hard code the lat/long it work so just need to understand the click.
I have a list of properties on one side and the map on the other. When I click on the address I want it to pan on the map.
I was reviewing this site:
https://stackoverflow.com/questions/14306098/google-maps-api-pan-to-markers-from-a-list
In my maps js I am using:
$("#contacts").on("click",
var laLatLng = new google.maps.LatLng({{p.Lat
map.panTo(laLatLng);
map.setZoom(5);
});
And on my list I am using:
<a href="javascript:void(0)" id="{{p.Matrix_Unique_ID}}
How do I register the click? That is the part I am not sure. If I hard code the lat/long it work so just need to understand the click.
ASKER
the issue is I don't have #contacts in my code. This is the part that is confusing me.
Ok. So, what element do you want to bind a click event to? Can you post the HTML for that element here?
ASKER
I want to bind this:
<a href="javascript:void(0)" id="{{p.Matrix_Unique_ID}} " data-city="{{p.Address}}"> Map</a>
Note: using twig so {{p.Matrix_Unique_ID}} is a unique ID and {{p.Address}} is an address
<a href="javascript:void(0)" id="{{p.Matrix_Unique_ID}}
Note: using twig so {{p.Matrix_Unique_ID}} is a unique ID and {{p.Address}} is an address
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! I ended up binding on ID and that is working now. I have some more troubleshooting to do but this has got me over the hump. Thank you very much!
ASKER
Here is my updated code:
Note: I am producing one of these for each property. Seams to run fine.
This is looped...
<a href="#" id="map_{{p.Matrix_Unique_ ID}}">Map< /a>
Then in my google maps JS:
This is looped...
$("#map_{{p.Matrix_Unique_ ID}}").on( "click", function() {
console.log('{{p.Matrix_Un ique_ID}}' );
var laLatLng = new google.maps.LatLng({{p.Lat itude}}, {{p.Longitude}});
map.panTo(laLatLng);
map.setZoom(12);
infoWindow.setContent("<di v style = 'width:200px;min-height:20 px'>" + data.description + "</div>");
infoWindow.open(map, marker);
});
Note: I am producing one of these for each property. Seams to run fine.
This is looped...
<a href="#" id="map_{{p.Matrix_Unique_
Then in my google maps JS:
This is looped...
$("#map_{{p.Matrix_Unique_
console.log('{{p.Matrix_Un
var laLatLng = new google.maps.LatLng({{p.Lat
map.panTo(laLatLng);
map.setZoom(12);
infoWindow.setContent("<di
infoWindow.open(map, marker);
});
Do you mean the click on #contacts ?
If so, you can put a console.log() inside the function that triggers on click, and verify it's firing.