I want to display a map with multiple markers and it should display numbers in the marker and also an infowindow with info from the array.
It shows all the markers but with the number 5 in all of them and it is displaying the "Maroubra Beach" in the info window on all.
The info window itself, works as it should, that is that it opens on every marker as it should, but is displaying the wrong text!
Im not sure what Im doing wrong with the counter!? Since it is displaying 5 in all markers.
var geocoder;
var map;
function initializemulti() {
//this is the geolocationmarker-compiled.js file
(function() {var c=null,e;
function f(b,a,d){var i={clickable:!1,cursor:"pointer",draggable:!1,flat:!0,icon:new google.maps.MarkerImage("https://google-maps-utility-library-v3.googlecode.com/svn/trunk/GeolocationMarker/images/gpsloc.png",new google.maps.Size(15,15),new google.maps.Point(0,0),new google.maps.Point(7,7)),optimized:!1,position:new google.maps.LatLng(0,0),title:"Current location",zIndex:2};a&&(i=g(i,a));a={clickable:!1,radius:0,strokeColor:"1bb6ff",strokeOpacity:0.4,fillColor:"61a0bf",fillOpacity:0.4,strokeWeight:1,
zIndex:1};d&&(a=g(a,d));this.a=new google.maps.Marker(i);this.b=new google.maps.Circle(a);this.b.bindTo("center",this.a,"position");this.b.bindTo("map",this.a);b&&this.e(b)}e=f.prototype;e.c=c;e.a=c;e.b=c;e.g=function(){return this.c};e.h=function(){return this.c?this.a.getPosition():c};e.f=function(){return this.c?this.b.getBounds():c};e.i=function(){return this.c?this.b.getRadius():c};e.d=-1;
e.e=function(b){if(this.c=b){var a=this,b={enableHighAccuracy:!0,maximumAge:1E3};navigator.geolocation&&(this.d=navigator.geolocation.watchPosition(function(d){var b=new google.maps.LatLng(d.coords.latitude,d.coords.longitude);a.b.setRadius(d.coords.accuracy);if(!a.a.getMap()||!b.equals(a.a.getPosition()))a.a.setPosition(new google.maps.LatLng(d.coords.latitude,d.coords.longitude)),a.a.setPosition(b),a.a.getMap()||a.a.setMap(a.c),google.maps.event.trigger(a,"position_changed",new h(b,a.b.getBounds(),
d.coords.accuracy))},function(b){google.maps.event.trigger(a,"geolocation_error",b)},b))}else navigator.geolocation.clearWatch(this.d),this.d=-1,this.a.setMap(b)};e.k=function(b){this.a.setOptions(g({},b))};e.j=function(b){this.b.setOptions(g({},b))};function g(b,a){for(var d in a)j[d]||(b[d]=a[d]);return b}var j={map:!0,position:!0,radius:!0};function h(b,a,d){b&&(this.position=b);a&&(this.bounds=a);d&&(this.accuracy=d)}h.prototype.position=c;h.prototype.bounds=c;h.prototype.accuracy=c;f.prototype.getAccuracy=f.prototype.i;f.prototype.getBounds=f.prototype.f;f.prototype.getMap=f.prototype.g;f.prototype.getPosition=f.prototype.h;f.prototype.setCircleOptions=f.prototype.j;f.prototype.setMap=f.prototype.e;f.prototype.setMarkerOptions=f.prototype.k;window.GeolocationMarker=f;})()
//alert("init");
var locations = [
['Big Boys Grill & Bar', '<br />Kungsgatan 28, Varberg'],
['Black Pearl Varberg', '<br />Kungsgatan 13, Varberg'],
['Bruket', '<br />Birger Svenssons väg 16 E, Varberg'],
['Comwell Varbergs Kurort', '<br />Nils Kreugers väg 5, Varberg']
];
var mapen = new google.maps.Map(document.getElementById('map_canvasmulti'), {
zoom: 12,
center: new google.maps.LatLng(57.111488,12.246623),
//center: undefined,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
//for displaying the current users location
var GeoMarker = new GeolocationMarker();
GeoMarker.setCircleOptions({fillColor: '#808080'});
google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
// mapen.setCenter(this.getPosition());
// mapen.fitBounds(this.getBounds());
});
google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
alert('There was an error obtaining your position. Message: ' + e.message);
});
GeoMarker.setMap(mapen);
var marker,i;
var markers = [];
var marker, i;
for (i = 0; i < locations.length; i++) {
var p = locations[i];
geocoder.geocode({
'address': locations[i][1]
}, (function(i,p) {
return function(results, status) {
//alert(status);
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
mapen.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
position: results[0].geometry.location,
icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=' + ([i+1]) + '|FF776B|000000',
map: mapen,
title: p[2]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(p[0] + p[1]);
infowindow.open(mapen, this);
});
// google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(mapen, this);});
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close();
});
} else {
alert("some problem in geocode" + status);
}
};
})(i,p));
}
}
Any input really appreciated, thanks!
Ok so this works, except for that the blue dots is not showing? The circle around the users location i showing, but not the blue dot?
Use anonymous function closure (doesn't have to be anonymous, named functions work as well) to keep the information associated with the geocode request (for use in the callback) and in the infowindow click event handler (for use when the marker is clicked).
var locations = [
['Bondi Beach', '850 Bay st 04 Toronto, Ont'],
['Coogee Beach', '932 Bay Street, Toronto, ON M5S 1B1'],
['Cronulla Beach', '61 Town Centre Court, Toronto, ON M1P'],
['Manly Beach', '832 Bay Street, Toronto, ON M5S 1B1'],
['Maroubra Beach', '606 New Toronto Street, Toronto, ON M8V 2E8']
];
var mapen = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 10,
center: new google.maps.LatLng(43.253205, -80.480347),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
var marker, i;
for (i = 0; i < locations.length; i++) {
var p = locations[i];
geocoder.geocode({
'address': locations[i][1]
}, (function(i,p) {
return function(results, status) {
//alert(status);
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
mapen.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
position: results[0].geometry.location,
icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=' + ([i]) + '|FF776B|000000',
map: mapen,
title: p[2]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(p[0]);
infowindow.open(mapen, this);
});
// google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(mapen, this);});
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close();
});
} else {
alert("some problem in geocode" + status);
}
};
})(i,p));
}
html,
body,
#map_canvas {
height: 100%;
margin: 0px;
padding: 0px;
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style="width: 100%; height: 100%;"></div>
Problem is you're loosing marker reference and only keeping the last one (note your array has 5 elements), to keep them, just create a markers[] array to store them:
var markers = [];
Then when marker is created add it to array
markers.push(marker);
Your code will be like this:
var locations = [
['Bondi Beach', '850 Bay st 04 Toronto, Ont'],
['Coogee Beach', '932 Bay Street, Toronto, ON M5S 1B1'],
['Cronulla Beach', '61 Town Centre Court, Toronto, ON M1P'],
['Manly Beach', '832 Bay Street, Toronto, ON M5S 1B1'],
['Maroubra Beach', '606 New Toronto Street, Toronto, ON M8V 2E8']
];
var mapen = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 10,
center: new google.maps.LatLng(43.253205,-80.480347),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
var marker,i;
var markers = [];
for (i = 0; i < locations.length; i++) {
var p = locations[i];
geocoder.geocode( { 'address': locations[i][1]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
mapen.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
position: results[0].geometry.location,
icon:'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld='+ ([i]) +'|FF776B|000000',
map: mapen,
title: p[2]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(p[0]);
infowindow.open(mapen, this);
});
google.maps.event.addListener(marker, 'mouseout', function() { infowindow.close();});
// insert created marker in the array
markers.push(marker);
}
else
{
alert("some problem in geocode" + status);
}
});
}
Related
Sory for my english, i want to create route direction with multiple marker in google maps, i try from this tutorial Direction with multipe marker
now i want to change the icon marker, the default marker is A,B,C,D like this screen shoot
my question is how to change the default icon with my icon...try to use directionsDisplay.setOptions( { suppressMarkers: true } );the icon si not appers....this my code:
var geocoder;
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var locations = [
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Maroubra Beach', -33.950198, 151.259302, 1],
['Cronulla Beach', -34.028249, 151.157507, 3]
];
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
directionsDisplay.setOptions( { suppressMarkers: true } );
var infowindow = new google.maps.InfoWindow();
var marker, i;
var request = {
travelMode: google.maps.TravelMode.DRIVING
};
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
icon:'images/dalamkota.png'
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
if (i == 0) request.origin = marker.getPosition();
else if (i == locations.length - 1) request.destination = marker.getPosition();
else {
if (!request.waypoints) request.waypoints = [];
request.waypoints.push({
location: marker.getPosition(),
stopover: true
});
}
}
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}
google.maps.event.addDomListener(window, "load", initialize);
Any wrong with my code....???
You are missing map: map part when creating markers:
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
icon:'http://s7.postimg.org/wg6bu3jpj/pointer.png',
map: map
});
JS fiddle: http://jsfiddle.net/4mtyu/2017/
Is there any way we can use our self made icon for the cluster other than the icons from the library?
This is my code, without the styles option the page works fine but with the styles option the map doesn't load along with the rest of the markers
var longitude = position.coords.longitude;
var latitude = position.coords.latitude;
var latLong = new google.maps.LatLng(latitude, longitude);
var locations = [
['Bondi Beach','nepal', 27.893, 85.667, 4],
['Coogee Beach','nepal', 27.883, 85.657, 5],
['Cronulla Beach', 'nepal', 27.873, 85.647, 3],
['Manly Beach', 'nepal',27.863, 85.637, 2],
['Maroubra Beach', 'nepal',27.69, 85.427, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: latLong,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI:true
});
var geomarker = new google.maps.Marker({
position: latLong,
map: map,
title: 'your location',
icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png'
});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(geomarker, 'click', (function(geomarker) {
return function() {
infowindow.setContent('You are here');
infowindow.open(map, geomarker);
}
})(geomarker));
var markers=[], i;
for (i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][2], locations[i][3])
//map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][1]);
infowindow.open(map, marker);
}
})(marker, i));
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers, {
styles: [{
url: '../img/logo.png'
}, {
url: '../imglogo.png'
}, {
url: '../img/logo.png'
}]);
Yes, according to the documentation:
http://gmaps-utility-library-dev.googlecode.com/svn/tags/markerclusterer/1.0/docs/reference.html
The MarkerClusterer constructor takes a MarkerClustererOptions object, which can contain an array of styles that include image URLs. The documentation is a bit lacking in actual examples demonstrating that, although you can see it happening here if you change the Cluster Style:
https://googlemaps.github.io/js-marker-clusterer/examples/advanced_example.html
I think you'd just need to do something like:
markerClusterer = new MarkerClusterer(map, markers, {
styles: [{
url: '../images/people35.png'
}, {
url: '../images/people45.png'
}, {
url: '../images/people55.png'
}]
});
This question already has answers here:
Google Maps JS API v3 - Simple Multiple Marker Example
(15 answers)
Closed 8 years ago.
Like many other people I'm finding identical values within my info windows. Alas, I've been using other posts in an attempt to troubleshoot. No luck.
Issue: Each of my infowindows shows the same values. Sigh.
Any help would be appreciated.
var map;
function initialize() {
var markers = [];
var mapOptions = {
zoom: 4,
scrollwheel: false,
streetViewControl: true,
panControl: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
// position: google.maps.ControlPosition.LEFT_CENTER
},
center: new google.maps.LatLng(-25.898854, 134.091377)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
setMarkers(map, beaches);
infowindow = new google.maps.InfoWindow({
content: "Loading..."
});
var input = /** #type {HTMLInputElement} */(
document.getElementById('pac-input'));
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var searchBox = new google.maps.places.SearchBox(
/** #type {HTMLInputElement} */(input));
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces();
for (var i = 0, marker; marker = markers[i]; i++) {
marker.setMap(null);
}
markers = [];
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {
var image = {
//url: 'assets/img/icon_pin.png',
//size: new google.maps.Size(40, 52),
//origin: new google.maps.Point(0, 0),
//anchor: new google.maps.Point(26, 20)
};
var marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
position: place.geometry.location
});
markers.push(marker);
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
});
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
}
var beaches = [
['Auburn', -33.847113, 151.04485, 1, '100', 'Parramatta', 'Road', 'Auburn', 'NSW', '2144', '02 7837 9800', '06:00 - 22:00', '06:00 - 22:00'],
['Balgowlah Platinum', -33.79284, 151.26376, 2, 'Shop 67, 197-215', 'Condamine', 'Street', 'Balgowlah', 'NSW', '2093', '1300 55 77 99', '06:00 - 21:30', '06:00 - 21:30'],
['Bankstown', -33.931208, 151.02895, 3, 'Unit 1-2, 9', 'Chapel', 'Street', 'South Bankstown', 'NSW', '2200', '02 8707 4700', '06:00 - 22:00', '06:00 - 22:00']
['Bayside', -37.954768, 145.03128, 4, '241 - 245', 'Bay', 'Road', 'Highett', 'VIC', '3190', '03 9559 7400', '06:00 - 22:00', '06:00 - 22:00']
];
function setMarkers(map, locations) {
var image = {
url: 'assets/img/icon_pin.png',
size: new google.maps.Size(40, 52),
origin: new google.maps.Point(0,0),
anchor: new google.maps.Point(26, 20)
};
var shape = {
coord: [1, 1, 1, 52, 40, 52, 40 , 1],
type: 'poly'
};
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
shape: shape
});
var contentString = '<div class="siteNotice"><h4>'+beach[0]+'</h4><p>'+beach[4]+' '+beach[5]+' '+beach[6]+' '+beach[7]+', '+beach[8]+', '+beach[9]+'</p><p><strong>Contact:</strong> '+beach[10]+'</p><p><strong>Opening Hours:</strong><br><span>Monday:</span> '+beach[11]+'<br><span>Tuesday:</span> '+beach[11]+'<br><span>Wednesday:</span> '+beach[11]+'<br><span>Thursday</span>: '+beach[11]+'<br><span>Friday:</span> '+beach[11]+'<br><span>Saturday</span>: '+beach[11]+'<br><span>Sunday:</span> '+beach[11]+'</p></div>';
google.maps.event.addListener(marker, "click", function () {
infowindow.setContent(contentString);
infowindow.open(map, this);
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
I had to create an array of info markers to hold the data.
var markers = [];
function addMapLocation(map, lat, long, title, message) {
var locationLatLong = new google.maps.LatLng(lat, long);
var locationMarker = new google.maps.Marker({ position: locationLatLong, map: map, title: title.trim() });
attachMessage(locationMarker, message);
markers.push(locationMarker);
}
function attachMessage(marker, message) {
var locationInfo = new google.maps.InfoWindow({ content: message });
google.maps.event.addListener(marker, 'click', function () { locationInfo.open(marker.get('map'), marker); });
}
I'm using MarkerClusterer to group markers and I have 2 questions:
What should I do to prevent the zoom on click and show an information
window instead, like when you click a marker?
Is there any way to change the icon of the cluster for the
markers? I don't want to use the earthquake-like icon as a group icon for my markers.
Thanks in advance.
EDIT
var marker;
var gm_map;
var markerArray = [];
var address = 'Sweden';
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
gm_map.setCenter(results[0].geometry.location);
gm_map.fitBounds(results[0].geometry.bounds);
} else {
alert("Kunde inte genomföra den geologiska inställningen på grund av följande fel:\n\n" + status);
}
});
function initialize() {
var marker, i;
var locations = [["content", 59.328626, 13.485686, 1]];
var options_googlemaps = {
minZoom: 4,
maxZoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
}
gm_map = new google.maps.Map(document.getElementById('google-maps'), options_googlemaps);
var options_markerclusterer = {
gridSize: 20,
maxZoom: 18
};
var markerCluster = new MarkerClusterer(gm_map, [], options_markerclusterer, {zoomOnClick: false});
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
alert('center of cluster: '+cluster.getCenter());
});
for(i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: gm_map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
$('#toggle-photolist').fadeIn();
$('#close-overlay').fadeIn();
$('#list-photos').html(locations[i][0]);
}
})(marker, i));
markerArray.push(marker);
markerCluster.addMarkers(markerArray, true);
}
}
$(document).ready(function() {
// INITIERA GOOGLE MAPS
initialize();
});
WORKING zoomOnClick
var options_markerclusterer = {
gridSize: 20,
maxZoom: 18,
zoomOnClick: false
};
var markerCluster = new MarkerClusterer(gm_map, [], options_markerclusterer);
re 1:
var markerCluster = new MarkerClusterer(map, markers ,{zoomOnClick: false});
google.maps.event.addListener(markerCluster,'clusterclick',
function(cluster){
alert('center of cluster: '+cluster.getCenter())
});
The details for the cluster (what info can you get out of it) can be found here:
https://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/markerclusterer/src/markerclusterer.js#801
You can simply show an infoWidow with the center set to cluster.getCenter() in the callback and you will be all set.
re2: Check out this sample with changed icons: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/advanced_example.html
HTH
You can try this for the info window, it worked perfectly fine for me! :)
//MarkerCluster!!!
var markerCluster = new MarkerClusterer(map, my_markers ,{zoomOnClick: false});
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
var content = '';
// Convert lat/long from cluster object to a usable MVCObject
var info = new google.maps.MVCObject;
info.set('position', cluster.center_);
iw.close();
iw.setContent('<h1>Hi this is my Info Window</h1>');
iw.open(map, info);
});
Working example here:
See http://krisarnold.com/2010/10/15/adding-info-windows-to-map-clusters-with-google-maps-api-v3/
I have 50 markers on my map (V3 of the Google maps API) in an array called spots. I want to add a text field so users can put in their postcode and it will add an additional marker giving them their location in relation to the surrounding markers. I think I am pretty close with what i have below but it won;t output the marker on the map. I think there is a conflict because i already have an array of markers and it doesn't like me adding the additional marker through the function. How do i get that function to add an additional element to the array through the codeAddress() function? Or is that even the right way to do it?
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(51.51251523, -0.133201961),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
setMarkers(map, spots);
}
var spots = [
['River Street - Clerkenwell', 51.52916347, -0.109970527, '3.png', 2896, 'River Street - Clerkenwell'],
['Phillimore Gardens - Kensington', 51.49960695, -0.197574246, '3.png', 2897, 'Phillimore Gardens - Kensington']
];
function setMarkers(map, locations) {
var image1 = new google.maps.MarkerImage('amber-spot.png',
new google.maps.Size(30, 36),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
for (var i = 0; i < locations.length; i++) {
var spot = locations[i];
var myLatLng = new google.maps.LatLng(spot[1], spot[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: spot[3],
title: spot[0],
zIndex: spot[4],
html: spot[5]
});
var infowindow = new google.maps.InfoWindow({
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(this.html);
infowindow.open(map,this);
});
}
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker2 = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
This is the form for geocoding
<div class="view-content">
<input id="address" type="textbox" value="W1T 4JD">
<input type="button" value="Geocode" onclick="codeAddress()">
<div id="map_canvas" style="width:800px; height:600px;"></div>
I ended up using the proximity postcode filter on the Drupal gmap module to do this. Initially i didn;t think it would work because i wasn't using the gmap modules native map on the View where the filter was being used but i hadn't realised the results would still be in the array that was returned :-).
Lee