Google maps zoom broken - google-maps

I've created a Google Maps overlay, but for some reason the zoom slider in the top-left of the map has stopped working. Have been trying to pick apart the code to fix it, but can't seem to find what is broken. Can someone have a look to see what I'm missing?
http://www.ucl.ac.uk/study/virtualtours/
My code is here:
<script type="text/javascript">
google.load("maps", "2");
google.load("jquery", "1.4.2");
var map;
var camera;
var side_bar_html = "";
var gmarkers = [];
function TileToQuadKey ( tx, ty, zl){
var quad = "";
for (var i = zl; i > 0; i--) {
var mask = 1 << (i - 1);
var cell = 0;
if ((tx & mask) != 0) cell++;
if ((ty & mask) != 0) cell += 2;
quad += cell;
}
return quad;
}
var uclvtTiles = function (a,b) {
var f = "http://www.ucl.ac.uk/prosp-students/access/virtual-tour/tourlayers/" + TileToQuadKey(a.x,a.y,b) + ".png";
return f;
}
function createUclVTSatMapType() {
var uclvtHybridLayer = new Array();
uclvtHybridLayer[0] = G_NORMAL_MAP.getTileLayers()[0];
uclvtHybridLayer[1] = new GTileLayer(new GCopyrightCollection('') , 17, 17);
uclvtHybridLayer[1].getTileUrl = uclvtTiles;
uclvtHybridLayer[1].getCopyright = function(a,b) {return "University College London, 2010";};
uclvtHybridLayer[1].getOpacity = function () {return 0.97;};//opacity of the non transparent part
if(navigator.userAgent.indexOf("MSIE") == -1) {
uclvtHybridLayer[1].isPng = function() {return true;};
}
var uclvtSatMap = new GMapType(
uclvtHybridLayer,
G_NORMAL_MAP.getProjection(),
'UCL Map',
{errorMessage:"", alt:"Show imagery with UCL Map"});
uclvtSatMap.getTextColor = function() {return "#000000";};
return uclvtSatMap;
}
function myclick(i) {
GEvent.trigger(gmarkers[i], 'click');
}
function addMarker(point, title, video, details) {
var marker = new GMarker(point, {title: title, icon:camera});
GEvent.addListener(marker, "click", function() {
if (details) {
marker.openInfoWindowTabsHtml([new GInfoWindowTab("Video", video),
new GInfoWindowTab("More", details)]);
} else {
marker.openInfoWindowHtml(video);
}
});
var id = gmarkers.length;
gmarkers.push(marker);
map.addOverlay(marker);
return id;
}
function flashMovieHTML(title, file) {
return '<div style="width:335px; height:260px">' +
'<b>' + title + '</b>' +
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="325" height="244" ' +
'id="' + title + '" ' +
'title="' + title + '">' +
'<param name="movie" value="http://www.ucl.ac.uk/prosp-students/access/virtual-tour/' + file + '" />' +
'<param name="quality" value="high" />' +
'<param name="wmode" value="opaque" />' +
'<param name="swfversion" value="8.0.35.0" />' +
'<embed src="http://www.ucl.ac.uk/prosp-students/access/virtual-tour/' + file + '" ' +
'quality="high" ' +
'width="325" ' +
'height="244" ' +
'name="' + title + '" ' +
'type="application/x-shockwave-flash" ' +
'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
'</embed>' +
'</object>' +
'</div>';
}
function addMarkersToMap() {
GDownloadUrl('campus.xml', function(doc) {
var xmlDoc = GXml.parse(doc);
var locations = xmlDoc.documentElement.getElementsByTagName("location");
var currentCategory = "";
for (var i = 0; i < locations.length; i++) {
var lat = parseFloat(locations[i].getAttribute("lat"));
var lng = parseFloat(locations[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var title = locations[i].getAttribute("title");
var menu = locations[i].getAttribute("menu");
var video = locations[i].getAttribute("video");
var category = locations[i].getAttribute("category");
var details = locations[i].childNodes.length == 0 ? null :
'<div style="width:335px; height:260px">' +
locations[i].childNodes[0].nodeValue +
'</div>';
var id = addMarker(point, title, flashMovieHTML(title, video), details);
if (category != currentCategory) {
if (id > 0) {
side_bar_html += '</ul></div></div>';
}
side_bar_html += '<div class="collapsable">';
side_bar_html += '<h4 class="toggleCollapsableContent">' + category + '</h4>';
side_bar_html += '<div class="collapsableContent"><ul>';
}
side_bar_html += '<li><a href="javascript:myclick(' + id + ')">' + menu + '<\/a></li>';
currentCategory = category;
}
side_bar_html += '</ul></div></div>';
document.getElementById("right").innerHTML = side_bar_html;
$("h4.toggleCollapsableContent:gt(0)")
.addClass('closed')
.next('.collapsableContent').hide();
$("h4.toggleCollapsableContent").click(function () {
if ($(this).next($(".collapsableContent")).is(":hidden")) {
$(this).next($(".collapsableContent")).slideDown("fast");
$(this).removeClass("closed");
} else {
$(this).next($(".collapsableContent")).slideUp("fast");
$(this).addClass("closed");
}
});
});
}
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("mapDiv"));
map.setCenter(new GLatLng(51.52484592590448, -0.13345599174499512), 17);
map.setUIToDefault();
var uclvtSatMapType = createUclVTSatMapType()
map.addMapType(uclvtSatMapType);
map.setMapType(uclvtSatMapType);
camera = new GIcon(G_DEFAULT_ICON);
camera.image = "ucl-video.png";
camera.iconSize = new GSize(32,37);
camera.iconAnchor = new GPoint(16,35);
camera.infoWindowAnchor = new GPoint(16,2);
addMarkersToMap();
}
}
google.setOnLoadCallback(initialize);
Cheers,
G

The div that holds this image
http://www.ucl.ac.uk/prosp-students/access/virtual-tour/campus-map-key.png
is positioned absolutely above the map and it blocking access to everything underneath it.

This may help you:
#map img{max-width: inherit;}

Related

Chrome Storage API keys getting reset

I am developing my first chrome extension. It highlights the words that are passed to it. I used storage API to save a few objects so when I open the extension again, it will retain what I highlighted. but once in a while, they get reset to the first string value of the object only.
https://www.screencast.com/t/0jF6AtCc
I went through the code for hours but there is nothing that could be doing this. i have tried them reassigning them in multiple places but nothing helped. There are no errors in both consoles.
popup.js
var rstr = [];
var rnum = [];
var rcolor = [];
var rfont = [];
chrome.storage.local.get(['htxt', 'hnum', 'hcolor', 'hfont'], function(result) {
if (result.hnum != null) {
rnum = (result.hnum);
rcolor = (result.hcolor);
rfont = (result.hfont);
rstr = (result.htxt);
}
if (rstr.length > 0) {
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
for (var j = 1; j <= rstr.length; j++) {
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt' + j + '"></input></td><td><input type="text" id="num' + j + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + j + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + j + '" style="width: 15px;"> </td> </tr> ';
}
for (var j = 1; j <= rstr.length; j++) {
document.getElementById("txt" + j).value = rstr[j - 1];
document.getElementById("num" + j).value = rnum[j - 1];
document.getElementById("bg" + j).value = rcolor[j - 1];
document.getElementById("font" + j).value = rfont[j - 1];
}
}
colorarr = ["#b1c7fd", "#ddfdb1", "#fdb1f3", "#b1fdf0", "#fddab1", "#c4b1fd", "#b4fdb1", "#FFFF00", "#FFA500"];
function getRandomColor() {
return colorarr[Math.floor(Math.random() * 9)];
}
document.getElementById("bg1").value = getRandomColor();
var i = 2;
var txt = [];
var num = [];
var color = [];
var font = [];
document.getElementById('btn').addEventListener('click', function() {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(activeTabs) {
txt = [];
num = [];
color = [];
font = [];
for (var j = 1; j < i; j++) {
if (document.getElementById("txt" + j).value != null) {
txt.push(document.getElementById("txt" + j).value);
num.push(document.getElementById("num" + j).value);
color.push(document.getElementById("bg" + j).value);
font.push(document.getElementById("font" + j).value);
}
}
chrome.storage.local.set({
"htxt": txt
});
chrome.storage.local.set({
"hnum": num
});
chrome.storage.local.set({
"hcolor": color
});
chrome.storage.local.set({
"hfont": font
});
chrome.tabs.executeScript(null, {
code: "var str=" + JSON.stringify(txt) + ";var numjson=" + JSON.stringify(num) + ";var color=" + JSON.stringify(color) + ";var font=" + JSON.stringify(font) + ";"
}, function() {
chrome.tabs.executeScript(null, {
file: 'highlight.js'
}, function(results) {
if (results != null) {
document.getElementById('scorevalue').innerHTML = results[0];
chrome.browserAction.setBadgeText({
text: results[0] ? results[0].toString() : "0"
});
}
});
});
});
});
document.getElementById('add').addEventListener('click', function() {
var tr = document.createElement('tr');
tr.innerHTML = '<td><input type="text" id="txt' + i + '"></input></td><td><input type="text" id="num' + i + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + i + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + i + '" style="width: 15px;"> </td> ';
document.getElementById('tbl').appendChild(tr);
document.getElementById("bg" + i).value = getRandomColor();
i++;
});
document.getElementById('delete').addEventListener('click', function() {
chrome.storage.local.remove(['htxt', 'hnum', 'hcolor', 'hfont'], function() {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
})
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt1"></input></td><td><input type="text" id="num1" style="width: 25px;" value=0></input></td><td><input type="color" id="bg1" style="width: 15px;"> </td> <td> <input type="color" id="font1" style="width: 15px;"> </td> </tr> ';
chrome.tabs.getSelected(null, function(tab) {
var code = 'window.location.reload();';
chrome.tabs.executeScript(tab.id, {
code: code
});
});
});
document.getElementById('bulk').addEventListener('click', function() {
document.getElementById('bulkdiv').innerHTML = "<textarea rows='4' cols='50' id='bulktext'></textarea><input id='bulkbtn' type=button value='Fill Up'>"
document.getElementById('bulkbtn').addEventListener('click', function() {
var res = document.getElementById('bulktext').value.split("\n");
i = res.length + 1;
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
for (var j = 1; j < i; j++) {
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt' + j + '"></input></td><td><input type="text" id="num' + j + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + j + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + j + '" style="width: 15px;"> </td> </tr> ';
}
for (var j = 1; j < i; j++) {
document.getElementById("txt" + j).value = res[j - 1].trim();
document.getElementById("bg" + j).value = getRandomColor();
}
console.log(res);
});
});
});
Highlight.js
function highlight(container, what, spanClass) {
var content = container.innerHTML,
pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', 'gi'),
replaceWith = '$1<span ' + (spanClass ? 'style=background:' + spanClass + ';' : '') + '">$2</span>$3',
highlighted = content.replace(pattern, replaceWith);
return (container.innerHTML = highlighted) !== content;
}
function num(container, what) {
if ((container.innerHTML.match(new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', "gi"))) != null) return container.innerHTML.match(new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', "gi")).length;
return 0;
}
chrome.storage.local.remove(['htxt', 'hnum', 'hcolor', 'hfont'], function() {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
var score = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] != '') {
console.log("inside highlight.js");
console.log(str[i]);
highlight(document.getElementsByTagName('body')[0], str[i], color[i]);
score += num(document.getElementsByTagName('body')[0], str[i]) * numjson[i];
}
}
chrome.storage.local.set({
"htxt": str
});
chrome.storage.local.set({
"hnum": numjson
});
chrome.storage.local.set({
"hcolor": color
});
chrome.storage.local.set({
"hfont": font
});
score;
});
There is an inject.js also which run on all pages with similar code to highlight.js. It was made so that pages get highlighted even when someone navigate away or reload the page. It is also accessing the Chrome Storage API.
Only popup.js have code to modify the key pairs in storage API but it still somehow get changed to the first string. Please help.
Here is an unpacked version of it.
https://drive.google.com/file/d/1icG6pa9xTGAJ6DO2Wgwn7LE5yG8CSRzz/

i want to use ajax variable in other function

I want to use modal, so i get the data value from ajax.
the data is like that [{'source_name': '인터넷', 'description': '여행자료', 'source_slug': '_1', 'subject_name': '여행', 'subject_slug': '_6'}]
I want to put the value of source_name "인터넷" to source_name variable.
I want to use soure_name variable at this line.
html += '<li><span> 출처 : ' + source_name + ''
but source_name is undefined.
please help me
this is code.
function showModal(){
var pk = $(this).find('img').attr('id');
$.ajax({
url : '/photo/' + pk + '/',
async: false,
success: function(data){
data= JSON.stringify(data)
var source_slug = data[0]["source_slug"];
var source_name = data[0]["source_name"];
var description = data[0]["description"];
var subject_slug = data[0]["subject_slug"];
var subject_name = data[0]["subject_name"];
}
});
var src = $(this).find('img').attr('src');
var largeImg = $(this).find('img').attr('data-bsp-large-src');
if(typeof largeImg === 'string'){
src = largeImg;
}
var index = $(this).attr('data-bsp-li-index');
var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
var theImg = $(this).find('img');
var pText = $(this).find('.text').html();
var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;
clicked.img = src;
clicked.prevImg = parseInt(index) - parseInt(1);
clicked.nextImg = parseInt(index) + parseInt(1);
clicked.ulIndex = ulIndex;
clicked.ulId = ulId;
$('#bsPhotoGalleryModal').modal();
var html = '';
var img = '<img src="' + clicked.img + '" class="img-responsive"/>';
html += img;
html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
html += '<div class="bsp-text-container">';
html += '<li><span> 출처 : ' + source_name + ''
html += '</span></li>'
html += '<li><span> 과목 및 단원 :' + subject_name + ''
html += '<li><span>' + description + '</span></li>'
html += '</div>';
html += '<a class="bsp-controls next" data-bsp-id="'+clicked.ulId+'" href="'+ (clicked.nextImg) + '"><span class="' + settings.iconRight + '"></span></a>';
html += '<a class="bsp-controls previous" data-bsp-id="'+clicked.ulId+'" href="' + (clicked.prevImg) + '"><span class="' + settings.iconLeft + '"></span></a>';
$('#bsPhotoGalleryModal .modal-body').html(html);
$('.bsp-close').on('click', closeModal);
showHideControls();
}
You need to make the change inside success not after:
function showModal(){
var pk = $(this).find('img').attr('id');
$.ajax({
url : '/photo/' + pk + '/',
async: false,
success: function(data){
data= JSON.stringify(data)
var source_slug = data[0]["source_slug"];
var source_name = data[0]["source_name"];
var description = data[0]["description"];
var subject_slug = data[0]["subject_slug"];
var subject_name = data[0]["subject_name"];
var src = $(this).find('img').attr('src');
var largeImg = $(this).find('img').attr('data-bsp-large-src');
if(typeof largeImg === 'string'){
src = largeImg;
}
var index = $(this).attr('data-bsp-li-index');
var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
var theImg = $(this).find('img');
var pText = $(this).find('.text').html();
var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;
clicked.img = src;
clicked.prevImg = parseInt(index) - parseInt(1);
clicked.nextImg = parseInt(index) + parseInt(1);
clicked.ulIndex = ulIndex;
clicked.ulId = ulId;
$('#bsPhotoGalleryModal').modal();
var html = '';
var img = '<img src="' + clicked.img + '" class="img-responsive"/>';
html += img;
html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
html += '<div class="bsp-text-container">';
html += '<li><span> 출처 : ' + source_name + ''
html += '</span></li>'
html += '<li><span> 과목 및 단원 :' + subject_name + ''
html += '<li><span>' + description + '</span></li>'
html += '</div>';
html += '<a class="bsp-controls next" data-bsp-id="'+clicked.ulId+'" href="'+ (clicked.nextImg) + '"><span class="' + settings.iconRight + '"></span></a>';
html += '<a class="bsp-controls previous" data-bsp-id="'+clicked.ulId+'" href="' + (clicked.prevImg) + '"><span class="' + settings.iconLeft + '"></span></a>';
$('#bsPhotoGalleryModal .modal-body').html(html);
$('.bsp-close').on('click', closeModal);
showHideControls();
}
});}

How do I format the directions output listing in Google Maps API V3?

I'm new to Google Maps API V3 and I have to use it to replace an older mapping app in one of our systems.
I've implemented a basic routing screen using the example at https://developers.google.com/maps/documentation/javascript/examples/directions-draggable
The basics are working well. The one thing that's bothering me is that I cannot find any clear discussion in the API of how to format the directions output listing. Nothing I've tried so far seems to affect it.
I'm simply doing a DirectionsRenderer.setPanel(div name) where the div has no properties other than a width of 1025px.
My chief irritations are that the directions themselves are only about 2/3 the width of the div and the text in the middle column looks like it's center justified. (The top and bottom of the list, the origin and destination addresses are the correct width.)
Is there any way to customize this or am I using too simple a model for my page?
The data used to render the directions panel is available in the result returned from the Directions Service, you can render it however you like by doing it manually.
Very simple example:
http://www.geocodezip.com/v3_directions_custom_icons_draggable.html
Custom Renderer:
function RenderCustomDirections(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var bounds = new google.maps.LatLngBounds();
var route = response.routes[0];
var summaryPanel = document.getElementById("directions_panel");
var detailsPanel = document.getElementById("direction_details");
startLocation = new Object();
endLocation = new Object();
summaryPanel.innerHTML = "";
detailsPanel.innerHTML = '<ul>';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment + "</b><br />";
summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
}
var path = response.routes[0].overview_path;
var legs = response.routes[0].legs;
for (i=0;i<legs.length;i++) {
if (i == 0) {
startLocation.latlng = legs[i].start_location;
startLocation.address = legs[i].start_address;
startLocation.marker = createMarker(legs[i].start_location,"start",legs[i].start_address,"green");
}
endLocation.latlng = legs[i].end_location;
endLocation.address = legs[i].end_address;
var steps = legs[i].steps;
for (j=0;j<steps.length;j++) {
var nextSegment = steps[j].path;
detailsPanel.innerHTML += "<li>"+steps[j].instructions;
var dist_dur = "";
if (steps[j].distance && steps[j].distance.text) dist_dur += " "+steps[j].distance.text;
if (steps[j].duration && steps[j].duration.text) dist_dur += " "+steps[j].duration.text;
if (dist_dur != "") {
detailsPanel.innerHTML += "("+dist_dur+")<br /></li>";
} else {
detailsPanel.innerHTML += "</li>";
}
for (k=0;k<nextSegment.length;k++) {
polyline.getPath().push(nextSegment[k]);
bounds.extend(nextSegment[k]);
}
}
}
detailsPanel.innerHTML += "</ul>"
polyline.setMap(map);
map.fitBounds(bounds);
endLocation.marker = createMarker(endLocation.latlng,"end",endLocation.address,"red");
// == create the initial sidebar ==
makeSidebar();
}
else alert(status);
}

Blogger API not retrieving all the post from a blog

I have a travel blog with blogspot. I have a page which displays a map of the world with the path taken so far. To do this, I use the blogger API to retrieve the location of each post as follow:
<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">
My issue is that it seems that only the last posts are retrieved and the first ones ignored. On the following link, the complete path should contain all the south of Argentina and be linked to the current path shown.
http://el-gato-lindo.blogspot.com/p/map.html
The complete code to generate the map is as follow:
<html>
<body>
<div id="content">
</div>
<div align="center" id="googleMap" style="height: 900px; width: 620px;">
</div>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry" type="text/javascript"></script>
<script>
var Lat = new Array();
var Lng = new Array();
var Place = new Array();
var TitlePost = new Array();
var UrlPost = new Array();
var DatePost = new Array();
// Get latitude/longitude from Blogger
function handleResponse(response) {
for(i=0; i< response.items.length; i++){
if(response.items[i].location != undefined){
Lat.push(response.items[i].location.lat);
Lng.push(response.items[i].location.lng);
Place.push(response.items[i].location.name);
TitlePost.push(response.items[i].title);
UrlPost.push(response.items[i].url);
DatePost.push(response.items[i].published);
}
}
}
// Distance btw two places in km
function calcDistance(p1, p2){
return (google.maps.geometry.spherical.computeDistanceBetween(p1,p2)/1000).toFixed(2);
}
// Name of months for date formatting
var m_names = new Array();
m_names.push("January");
m_names.push("February");
m_names.push("March");
m_names.push("April");
m_names.push("May");
m_names.push("June");
m_names.push("July");
m_names.push("August");
m_names.push("September");
m_names.push("October");
m_names.push("November");
m_names.push("December");
// Create the map based on locations retrieved from Blogger
function initialize(){
// Get all latitude and longitude
var pos = new Array();
// Get the path
for(var i=0; i<Lat.length; i++){
pos[i]=new google.maps.LatLng(Lat[i],Lng[i]);
}
// Get the last position
var lastpos=new google.maps.LatLng(Lat[0],Lng[0]);
// Create the map
var mapProp = {
center:lastpos,
zoom:4,
mapTypeId:google.maps.MapTypeId.TERRAIN,
navigationControl:true,
streetViewControl:false
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
// Create the path
var flightPath = new google.maps.Polyline({
path:pos,
strokeColor:"#EE0000",
strokeOpacity:0.6,
strokeWeight:7,
clickable:false,
map:map
});
// Create invisible marker at each destination
var markerPos = new Array();
var infowindow = null;
for(var i=0; i<pos.length; i++){
marker=new google.maps.Marker({
position:pos[i],
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale:5,
fillOpacity:0,
strokeOpacity:0
},
clickable:true,
map:map
});
// Click on marker: Show infowindow with articles
google.maps.event.addListener(marker, 'click', function() {
// Articles posted within a given distance from point clicked will be shown
var toldist = 2048 / Math.pow(2,map.zoom); //km
str = '<div id="infowindow_listposts">';
for(var j=0; j<pos.length; j++){
if(pos[j] === this.position){
var optplace = j;
str += "<h1>
" + Place[j] + "</h1>
<br>";
}
}
str += "<ul>";
for(var j=0; j<pos.length; j++){
var dist = calcDistance(pos[j],this.position);
if(dist < toldist){
date = new Date(DatePost[j]);
str += "<li> <h2>
<a href='" + UrlPost[j] + "'>" + TitlePost[j] + "</a> <i>(";
str += m_names[date.getMonth()] + " " + date.getDate() + ", ";
str += date.getFullYear() + ") </i></h2>
</li>
";
}
}
str += "</ul>
";
str += "<i> Articles shown were written less than ";
if(toldist >= 1)
str += toldist + "km away from ";
else
str += 1000*toldist + "m away from ";
str += Place[optplace] + ".</i>";
str += "</div>
";
if (infowindow){
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content:str
});
infowindow.open(map,this);
});
markerPos.push(marker);
}
// Create the marker of last position
var lastmarker=new google.maps.Marker({
position:lastpos,
clickable:false,
map:map
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">
</script>
</body>
</html>
Thanks a lot for your help! I am currently travelling and it is quite difficult to solve this issue!
Nicolas
Try replacing
<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts?callback=handleResponse&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">
with
<script src="https://www.googleapis.com/blogger/v3/blogs/3089072491354463482/posts/default?redirect=false&start-index=1&max-results=500?callback=handleResponse&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU">

Upgrade Google-Maps API from V2 to V3

I'm trying to convert Google Maps API V2 into V3 but I cannot get it to work, I been trying for 3 days now and it's not working :-(
If someone can please tell me how to do this correctly I would be very thankful...
V2 Code
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA4vJ90IKcF0qHxC2Cg9NjchT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ-rtrvY-Stu0L_q-OypfOv3WnUfg"
type="text/javascript"></script>
<script type="text/javascript">
var geocoder, location1, location2, gDir, getCityName, getcITIESName, getDeliveryCityName, PickState, DeliveryState, SteState, SteStateB2, theAddress1, memeaddress1, memeaddress2;
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = (gDir.getDistance().meters / 1609.344).toFixed(0);//for 0 decial place
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
//theAddress1 = location1.address
getCityName = location1.address.split(",")
memeaddress1 = getCityName[0] + ',' + getCityName[1];
getcITIESName = location2.address.split(",");
memeaddress2 = getcITIESName[0] + ',' + getcITIESName[1].substr(0,3);
SteState = document.getElementById('selFromState').options[document.getElementById('selFromState').options.selectedIndex].value;
SteStateB2 = document.getElementById('selToState').options[document.getElementById('selToState').options.selectedIndex].value;
if (document.getElementById("inputString").value + ', ' + SteState == memeaddress1)
{
}
else
{
doItagain=confirm('Cannot find the Pickup City!\n\nDid you mean: ' + location1.address + ' ?' + '\n\nPress OK to Change\nCancel to keep the City and State you entered!\n\n\n');
if(doItagain){
getCityName[1] = (getCityName[1]).replace(/^\s*|\s*$/g,'');
var showonlythefirst2ltrspickup = getCityName[1].substr(0,2)
document.getElementById("inputString").value = getCityName[0]
document.getElementById("selFromState").value = showonlythefirst2ltrspickup;
showLocation()
}
else
// Just end and exit function
window.alert('Please Note you must enter the miles manually!')
document.getElementById("txtMiles").value = "0";
//}
}
if (document.getElementById("inputString2").value + ', ' + SteStateB2 == memeaddress2)
{
document.getElementById("txtMiles").value = drivingDistanceMiles;
checkemptyB2();
}
else
{
doIt=confirm('Cannot find the Delivery City!\n\nDid you mean: ' + location2.address + ' ?' + '\n\nPress OK to Change\nCancel to keep the City and State you entered!\n\n\n');
if(doIt){
getcITIESName[1] = (getcITIESName[1]).replace(/^\s*|\s*$/g,'');
var showonlythefirst2ltrs = getcITIESName[1].substr(0,2)
document.getElementById("inputString2").value = getcITIESName[0]
document.getElementById("selToState").value = showonlythefirst2ltrs;
showLocation()
}
else
// Just end and exit function
window.alert('Please Note you must enter the miles manually!')
document.getElementById("txtMiles").value = "0";
}
});
}
function showLocation() {
checkemptyB2();
//geocoder = new GClientGeocoder();
//gDir = new GDirections();
//alert("here is the pickup address:" + document.getElementById("inputString2").value + ',' + document.getElementById("selToState").value)
geocoder.getLocations(document.getElementById("inputString").value + ',' + document.getElementById("selFromState").value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the pickup address");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(document.getElementById("inputString2").value + ',' + document.getElementById("selToState").value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the delivery address");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address:
response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}
});
}
});
}
</script>
<script type="text/javascript">
function changedelivery() {
doIt=confirm('do you wish to proceed?');
if(doIt){
document.getElementById("inputString2").value = getcITIESName[0]
document.getElementById("selToState").value = SteStateB2
}
else{
// Just end and exit function
}
}
</script>
Here is the code that I tried:
<script type="text/javascript">
var geocoder,location1,location2,gDir,getCityName,getcITIESName,getDeliveryCityName,PickState,DeliveryState,SteState,SteStateB2,theAddress1,memeaddress1,memeaddress2;
function initialize() {
geocoder = new google.maps.Geocoder();
gDir = new google.maps.DirectionsService();
google.maps.Event.addListener(gDir, "load", function() {
var drivingDistanceMiles = (gDir.getDistance().meters / 1609.344).toFixed(0);//for 0 decial place
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
getCityName = location1.address.split(",")
memeaddress1 = getCityName[0] + ',' + getCityName[1];
getcITIESName = location2.address.split(",");
memeaddress2 = getcITIESName[0] + ',' + getcITIESName[1].substr(0,3);
SteState = document.getElementById('selFromState').options[document.getElementById('selFromState').options.selectedIndex].value;
SteStateB2 = document.getElementById('selToState').options[document.getElementById('selToState').options.selectedIndex].value;
if (document.getElementById("inputString").value + ', ' + SteState == memeaddress1)
{
}
else
{
doItagain=confirm('Cannot find the Pickup City!\n\nDid you mean: ' + location1.address + ' ?' + '\n\nPress OK to Change\nCancel to keep the City and State you entered!\n\n\n');
if(doItagain){
getCityName[1] = (getCityName[1]).replace(/^\s*|\s*$/g,'');
var showonlythefirst2ltrspickup = getCityName[1].substr(0,2)
document.getElementById("inputString").value = getCityName[0]
document.getElementById("selFromState").value = showonlythefirst2ltrspickup;
showLocation()
}
else
// Just end and exit function
window.alert('Please Note you must enter the miles manually!')
document.getElementById("txtMiles").value = "0";
//}
}
if (document.getElementById("inputString2").value + ', ' + SteStateB2 == memeaddress2)
{
document.getElementById("txtMiles").value = drivingDistanceMiles;
checkemptyB2();
}
else
{
doIt=confirm('Cannot find the Delivery City!\n\nDid you mean: ' + location2.address + ' ?' + '\n\nPress OK to Change\nCancel to keep the City and State you entered!\n\n\n');
if(doIt){
getcITIESName[1] = (getcITIESName[1]).replace(/^\s*|\s*$/g,'');
var showonlythefirst2ltrs = getcITIESName[1].substr(0,2)
document.getElementById("inputString2").value = getcITIESName[0]
document.getElementById("selToState").value = showonlythefirst2ltrs;
showLocation()
}
else
// Just end and exit function
window.alert('Please Note you must enter the miles manually!')
document.getElementById("txtMiles").value = "0";
}
});
}
function showLocation() {
checkemptyB2();
geocoder.geocode(document.getElementById("inputString").value + ',' + document.getElementById("selFromState").value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the pickup address");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.geocode(document.getElementById("inputString2").value + ',' + document.getElementById("selToState").value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the delivery address");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address:
response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}
});
}
});
}
</script>
<script type="text/javascript">
function changedelivery() {
doIt=confirm('do you wish to proceed?');
if(doIt){
document.getElementById("inputString2").value = getcITIESName[0]
document.getElementById("selToState").value = SteStateB2
}
else
{
// Just end and exit function
}
}
</script>
Thanks again for any help with this!
Anything that starts with a "G" is a v2 class. You need to replace:
GClientGeocoder(); -> google.maps.Geocoder
GDirections(); -> google.maps.DirectionsService & google.maps.DirectionsRenderer
With their v3 equivalents. They are different, see the documentation for details.