Hi Max,
The code I was trailing was provided by Marina Brodina in responce to another users question. I placed this in the javascript file in my project and was calling it on a click event on a button on the page.The function is below and the code in the click event was originally:
initiate_geolocation();
;
When this did not work I placed the tester function in the javascript and replaced the original call on the buttons click event to try to pop an alert purely to prove if
the script was getting called, this did not work either.
Regards,
Joe
The script file 'main':
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("GPS function not available right now");
break;
case error.POSITION_UNAVAILABLE: alert("Location services not turned on! Please enable location services prior to continuing.");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){
alert('Lat: ' + position.coords.latitude +
' Lon: ' + position.coords.longitude);
}
var lat;
var lon;
var onSuccess = function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
Code: Select all
var location = new google.maps.LatLng( lat,lon);
var myOptions = {
zoom: 4,
center: location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map($('div[dsid="mapa"]').get(0), myOptions);
var marker = new google.maps.Marker({
position: location,
map: map,
title:"Hello World!"
});
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
Code: Select all
function testalert(){
alert('Test Alert');
}