Hello I am stuck with a problem. I am trying to get the current postion in Google Maps with help of Java Script. It's a programming course I am not allowed to hardcode or so called static it has to work for every location. Here is my code:
var index = 0;
var yCoords = "dummy";
var contentstring = [];
var regionlocation = [];
var markers = [];
var iterator = 0;
var areaiterator = 0;
var map;
var infowindow = [];
geocoder = new google.maps.Geocoder();
$(document).ready(function () {
setTimeout(function() { initialize(); }, 400);
});
function initialize() {
infowindow = [];
markers = [];
GetValues();
iterator = 0;
areaiterator = 0;
region = new google.maps.LatLng(regionlocation[areaiterator].split(',')[0], regionlocation[areaiterator].split(',')[1]);
map = new google.maps.Map(document.getElementById("Map"), {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: region,
});
drop();
}
function GetValues() {
//Get the Latitude and Longitude of a Point site : http://ift.tt/uLinUG
contentstring[index] = "BTH Karlshamn<br><a target='_blank' href='http://ift.tt/1KEbhP3'>Webbutveckling</a><br><a href='http://www.bth.se/dite'>DITE</a>";
regionlocation[index] = '56.164226, 14.866160';
index++;
contentstring[index] = "Campus Gräsvik<br><a href='http://www.bth.se'>BTH</a>";
regionlocation[index] = '56.182034, 15.591874';
index++;
contentstring[index] = "Mattias Schertell<br><img src='http://ift.tt/1L1tnXc' width='20px' heught='25px'>";
regionlocation[index] = "56.258169, 15.630122";
index++;
contentstring[index] = "edLaika's Palace<br><img src='http://ift.tt/1KEbhP6' width='20px' heught='25px'>";
regionlocation[index] = "56.261976, 14.764781";
index++;
}
function drop() {
for (var i = 0; i < contentstring.length; i++) {
setTimeout(function() {
addMarker();
}, 800);
}
}
function addMarker() {
var address = contentstring[areaiterator];
var icons = 'http://ift.tt/Jp3W8N';
var templat = regionlocation[areaiterator].split(',')[0];
var templong = regionlocation[areaiterator].split(',')[1];
var temp_latLng = new google.maps.LatLng(templat, templong);
markers.push(new google.maps.Marker(
{
position: temp_latLng,
map: map,
icon: icons,
draggable: false
}));
iterator++;
info(iterator);
areaiterator++;
}
function info(i) {
infowindow[i] = new google.maps.InfoWindow({
content: contentstring[i - 1]
});
infowindow[i].content = contentstring[i - 1];
google.maps.event.addListener(markers[i - 1], 'click', function() {
for (var j = 1; j < contentstring.length + 1; j++) {
infowindow[j].close();
}
infowindow[i].open(map, markers[i - 1]);
});
}
Any suggestions I am new to JS. Thanks It should get and show the current postion on the map. I have tried some examples in Stack Overflow they don't work.
Aucun commentaire:
Enregistrer un commentaire