Hello,
I have a problem with Geocoder.
I must click twice a input button that has a onclick statement.
In IE8 i get the results direct back from google.maps.Geocoder but in
FF or on mobile divices I must click this button twice.
I use a seperate .js file for javascript.
[CODE]
// JavaScript Document - Google Maps API
//Globale variable
var directionsService = new google.maps.DirectionsService();
var wings = new google.maps.LatLng(51.71733,5.57172);
var start;
var directionDisplay;
var geocoder;
var map;
var stepDisplay;
var markerArray = [];
var from;
var state;
function initialize() {
//Initialize Googel Maps API
var kaart = new google.maps.LatLng(51.71624,5.57121);
var geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 15,
center: kaart,
navigationControl: false,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
position: google.maps.ControlPosition.TOP
},
scaleControl:false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var rendererOptions = {
map: map,
suppressMarkers: true
}
directionsDisplay = new
google.maps.DirectionsRenderer(rendererOptions)
//Show mesage window ad THE Wings marker
var contentString = '<h2 id="firstHeading"
class="firstHeading">M.V.C. The Wings</h2>'+
'<div id="bodyContent">'+
'<p>Hoenderbosscheweg<br />'+
'5388<br />'+
'Nistelrode</p>'+
'<a href="http://www.thewings.nl">'+
'TheWings.nl</a></p>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
//Marker The Wings
var m_image = new google.maps.MarkerImage('images/marker.png',
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(12, 34));
//Shadow Marker The Wings
var m_shadow = new google.maps.MarkerImage('images/
marker_shadow.png',
new google.maps.Size(40, 37),
new google.maps.Point(0,0),
new google.maps.Point(12, 37));
//Place Markers The Wings on the map
var marker = new google.maps.Marker({
position: wings,
draggable: false,
animation: google.maps.Animation.DROP,
map: map,
shadow: m_shadow,
icon: m_image,
title:"M.V.C. The Wings"
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
stepDisplay = new google.maps.InfoWindow();
}
function calcRoute() {
var totallength;
var adres = getAdress();
// First, clear out any existing markerArray
// from previous calculations.
for (i = 0; i < markerArray.length; i++) {
markerArray[i].setMap(null);
document.getElementById("Route").innerHTML = "";
}
if (adres) {
codeAddress(adres);
if (state) {
getRoute();
}
else alert ("Straat, Postcode en/of Plaats niet correct
opgegeven.");
}
}
function getAdress() {
//Retrieve start from the FORM elemants
form = document.Routeplanner;
if (form.elements['Straat'].value && form.elements['Postcode'].value
&& form.elements['Plaats'].value) {
var Straat = form.elements['Straat'].value;
var Post = form.elements['Postcode'].value;
Post = Post.substr(0,4);
var Plaats = form.elements['Plaats'].value;
var adres = Straat + ", " + Post + Plaats;
return adres;
}
else alert ("Vul wel uw Straat, Postcode en Plaats in.");
}
function codeAddress(address) {
//Decode input adsress to LatIng
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
start = results[0].geometry.location;
state = true;
}
else state = false;
});
//alert("Route wordt berekent!");
}
function getRoute(){
// With start and end locations created
// a DirectionsRequest using DRIVING directions.
var waypoint = new google.maps.LatLng(51.70497, 5.57097);
var request = {
origin: start,
destination: wings,
waypoints: [
{
location:waypoint,
stopover:false
}],
provideRouteAlternatives: false,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
// Route the directions and pass the response to a
// function to create markers for each step.
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var warnings = document.getElementById("warnings_panel");
warnings.innerHTML = "" + response.routes[0].warnings +
"";
directionsDisplay.setDirections(response);
showSteps(response);
}
document.getElementById("Route").innerHTML += '<table
class="tabel"><tr><td class="cell"></td><td>Totaal: ' +
response.routes[0].legs[0].distance.text + '</td></tr></table>';
});
}
function showSteps(directionResult) {
// For each step, place a marker, and add the text to the marker's
// info window. Also attach the marker to an array so we
// can keep track of it and remove it when calculating new
// routes.
var myRoute = directionResult.routes[0].legs[0];
for (var i = 0; i < myRoute.steps.length; i++) {
var marker = new google.maps.Marker({
position: myRoute.steps[i].start_point,
map: map,
title: 'Punt: ' + (i+1)
});
attachInstructionText(marker, i, myRoute.steps[i].instructions,
myRoute.steps[i].distance.text);
markerArray[i] = marker;
}
}
function attachInstructionText(marker, i, text, travel) {
var warnings = document.getElementById("Route");
warnings.innerHTML += '<table class="tabel"><tr><td
class="cell">' +
(i+1) + ' </td><td>' + text + '</td></tr><tr></td><td><td>Volgende
punt over: ' + travel + '</td></tr></table>';
google.maps.event.addListener(marker, 'click', function() {
stepDisplay.setContent('Punt: ' + (i+1) + '<br />' + text +
'<br /
>Volgende punt over: ' + travel);
stepDisplay.open(map, marker);
});
}
[/CODE]
Please what do I wrong?
Thank You,
Rob
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.