jquery - Get value from brackets from an onclick -
is possible lat , lon onclick
function?
<a href="javascript:void(0)" onclick="findlocation('6.443663,3.419248');return false;" id="lagos">lagos, nigeria</a> <a href="javascript:void(0)" onclick="findlocation('3.15021, 101.707703');return false;" id="kuala">kuala lupar, malaysia</a> <a href="javascript:void(0)" onclick="findlocation('24.9952447639, 55.0559356887');return false;" id="dubai">dubai, u.a.e.</a>
i have numbers findlocation
function array if possible each location.
added note findlocation
function plots locations on map , focuses in on location. need try lat , lon each onclick , somehow these plot points when page loads.
function findlocation(address) { var address = document.forms[0].q.value = address; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); marker = new google.maps.marker({ map: map, position: results[0].geometry.location }); // marker.setmap(null); } else { alert('geocode not successful following reason: ' + status); } }); }
are looking
var obj = {}; $('a').each(function(){ var $this = $(this); var text = $this.attr('onclick').replace('findlocation(\'', '').replace('\');return false;', ''); var array = text.split(',') obj[this.id]= [parsefloat(array[0]), parsefloat(array[1])]; }); console.log(obj)
demo: fiddle
Comments
Post a Comment