I want to use both of multiple markers (places) and geolocation in google maps.
Everything will be fine , if i can use resultx variable at this row
center: new google.maps.LatLng('42','26',13),
instead of '42','26'
i tried resultx,'resultx','+resultx+'.. such as but it doesnt work.
So what is your advice?
-----HTML----
<div id="map-canvas"></div>
<button onclick="getLocation()">Get your location</button>
-----JAVASCRIPT----
<script>
var x = document.getElementById("map-canvas");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latx=''+position.coords.latitude+'';
var lonx=''+position.coords.longitude+'';
var resultx=latx+','+lonx;
var locations = [
['Helooo',40, 30 ,0] , ['Helooo',41.04564,28.97862 ,1] , ];
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 5,
scrollwheel: false,
center: new google.maps.LatLng('42','26',13),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
disableAutoPan: true,
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
</script>
See Question&Answers more detail:os