Following example developed with angular.
Design link: https://github.com/emirdeliz/meus-projetos/tree/master/google-maps-custom/src/main/webapp
App:
var app = angular.module("GoogleMapsCustom", ["uiGmapgoogle-maps"]);
Controller:
app.controller("GoogleMapsCustomController", function($scope) {
$scope.map = { center: { latitude: -23.586172, longitude: -46.657085 }, zoom: 10};
$scope.map.randomMarkers = [];
var adressOfCustomer = [
["BAZAR BARAO LTDA ME", "AV.JOAO XXIII,84-V.FORMOSA, SP"],
["MAGAZINE BELEZA CENTER LTDA", "AV DOS IGARAPES, 1571, SP"],
["ESTACIONAMENTO CARREIRA LTDA ME", "AV.SAPOPEMBA,3016 SAPOPEMBA, SP"],
["LUIS GONZAGA GARDINALI ME", "R.FREI CANECA,22 - CENTRO, SP"],
["A R NETTO", "R.ANTONIO GONCALVES TEIXEIRA, 53, SP"],
["O DONEGA MOJI MIRIM ", "R.BUTANTA, 17-PINHEIROS, SP"],
["MAGAZINE MISS ELEGAN LTDA", "R GOVERNADOR PEDRO DE TOLEDO 1021, SP"],
["O.Y.OKI & CIA.LTDA ", "R.JOSE BONIFACIO,60, SP"]
];
$scope.setMarkers = function(numberOfMarkers) {
setLatitudeAndLongitudeByAdress(adressOfCustomer, $scope.map);
};
$scope.onMarkerClicked = function(marker){
marker.showWindow = true;
$scope.$apply();
};
});
app.controller("InfoController", function($scope) {
$scope.templateValue = 'hello from the template itself';
$scope.clickedButtonInWindow = function() {
var msg = 'clicked a window in the template!';
$log.info(msg);
alert(msg);
}
});
function setLatitudeAndLongitudeByAdress(adressOfCustomer, map){
var geocoder = new google.maps.Geocoder();
angular.forEach(adressOfCustomer, function(value, key) {
var adress = value[1];
geocoder.geocode({ 'address': adress + ', Brasil', 'region': 'BR' }, function (results, status) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var customer = value[0];
var itemMap = {
latitude : latitude,
longitude : longitude,
title : customer,
id : key,
adress : adress,
date : "10/11/2015"
};
map.randomMarkers.push(itemMap);
});
});
}
function init(){
var adressOfCustomer = [
["BAZAR BARAO LTDA ME", "AV.JOAO XXIII,84-V.FORMOSA, SP"],
["MAGAZINE BELEZA CENTER LTDA", "AV DOS IGARAPES, 1571, SP"],
["ESTACIONAMENTO CARREIRA LTDA ME", "AV.SAPOPEMBA,3016 SAPOPEMBA, SP"],
["LUIS GONZAGA GARDINALI ME", "R.FREI CANECA,22 - CENTRO, SP"],
["A R NETTO", "R.ANTONIO GONCALVES TEIXEIRA, 53, SP"],
["O DONEGA MOJI MIRIM ", "R.BUTANTA, 17-PINHEIROS, SP"],
["MAGAZINE MISS ELEGAN LTDA", "R GOVERNADOR PEDRO DE TOLEDO 1021, SP"],
["O.Y.OKI & CIA.LTDA ", "R.JOSE BONIFACIO,60, SP"]
];
var locationOfCustomer = getLatitudeAndLongitudeByAdress(adressOfCustomer);
initializeMaps(locationOfCustomer);
}
Index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Maps API v3: Busca de endereço e Autocomplete - Demo</title>
<link rel="stylesheet" type="text/css" href="assets/css/custom.css">
</head>
<body ng-app="GoogleMapsCustom">
<h1>Google Maps Multiple Marker Demo 123</h1>
<div ng-controller="GoogleMapsCustomController" ng-init="setMarkers();">
<ui-gmap-google-map center="map.center" zoom="map.zoom"> <ui-gmap-markers models="map.randomMarkers" coords="'self'" icon="'icon'" click="onMarkerClicked" doCluster="map.doClusterRandomMarkers"
clusterOptions="map.clusterOptions" modelsbyref="true">
<ui-gmap-windows show="'showWindow'" closeClick="'closeClick'" ng-cloak>
<div>
<p ng-non-bindable>{{title}} - endereço: {{adress}} visita: {{date}}<button type='button'>Incluir na Agenda</button></p>
</div>
</ui-gmap-windows>
</ui-gmap-markers>
</ui-gmap-google-map>
</div>
</body>
</html>
I will study, but how will I get the correct lat and Lon of the address ? For in your example appeared several. and how would plot on the map ? It would have to make an example ne some site ?
– Renan Rodrigues
@Renanrodrigues use the key
GEOMETRIC_CENTER
. This indicates, literally, the medium of the selected structure.– OnoSendai
how do I pass the json information to geocoder ? Help me with this ?
– Renan Rodrigues
@Renanrodrigues The Geocoder receives text (via
QueryString
) and returns a JSON. I updated the response with an example map view.– OnoSendai
Where in your code you pass the address ?
– Renan Rodrigues
@Renanrodrigues on the first link present in my reply.
– OnoSendai
Because this part is ok. However how will I get the lat and the long of the address I have from the database ?
– Renan Rodrigues
Like I don’t know how I’ll send the link address.
– Renan Rodrigues
@Renanrodrigues This is another question, which runs a little outside the scope of this. Feel free to create another question.
– OnoSendai
Friend take the last doubt, manage to make the request and is returning me the perfect json, however I am not able to access the lat and the long GEOMETRIC_CENTER. I’m doing next.
lat = dados.geometry.location.lat
and you’re not getting how I do this ?]– Renan Rodrigues
@Renanrodrigues try to
dados.results.geometry.location.lat
.– OnoSendai
Uncaught Typeerror: Cannot read Property 'Geometry' of Undefined
– Renan Rodrigues
Let’s go continue this discussion in chat.
– OnoSendai
After a long time searching, this answer helped me!
– Leonardo Max
@Leonardomax I’m happy to read this. Enjoy!
– OnoSendai