From 3603e1f576f1bd91d7fabe734e0faf08dbdaf9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Fri, 16 Dec 2016 17:45:02 -0500 Subject: [PATCH] Enchacement Google Maps Plugin --- plugin/google_maps/view/map_coordinates.tpl | 43 +++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/plugin/google_maps/view/map_coordinates.tpl b/plugin/google_maps/view/map_coordinates.tpl index 1816b4cadd..e5ebcd232b 100644 --- a/plugin/google_maps/view/map_coordinates.tpl +++ b/plugin/google_maps/view/map_coordinates.tpl @@ -6,11 +6,41 @@ initMap(); }); + function addMaker(lat, lng, map, bounds, userInfo) { + + var location = new google.maps.LatLng(lat, lng); + + var infoWindow = new google.maps.InfoWindow(); + + var geocoder = geocoder = new google.maps.Geocoder(); + + var marker = new google.maps.Marker({ + map: map, + position: location, + label: userInfo.complete_name + }); + var address = ""; + + geocoder.geocode({ 'latLng': location }, function (results) { + + address = results[1].formatted_address; + + var infoWinContent = "" + userInfo.complete_name + " - " + address; + + marker.addListener('click', function() { + infoWindow.setContent(infoWinContent); + infoWindow.open(map, marker); + }); + }); + + bounds.extend(marker.position); + map.fitBounds(bounds); + } + function initMap() { var center = new google.maps.LatLng(-3.480523, 7.866211); var bounds = new google.maps.LatLngBounds(); - var infoWindow = new google.maps.InfoWindow(); var map = new google.maps.Map(document.getElementById("map"), { zoom: 2, @@ -31,18 +61,9 @@ var lat = latLng[0]; var lng = latLng[1]; - var location = new google.maps.LatLng(lat, lng); - {% set userInfo = field.itemId | user_info %} - var marker = new google.maps.Marker({ - map: map, - position: location, - label: "{{ userInfo.complete_name }}" - }); - - bounds.extend(marker.position); - map.fitBounds(bounds); + addMaker(lat, lng, map, bounds, {{ userInfo|json_encode }}); {% endfor %}