157
rated 0 times
[
158]
[
1]
/ answers: 1 / hits: 19534
/ 12 Years ago, tue, january 8, 2013, 12:00:00
Hi all I have the following code:
var map;
var infowindow;
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(initialize);
}
else{x.innerHTML=Geolocation is not supported by this browser.;}
}
function initialize(position) {
var pyrmont = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 500,
types: ['restaurant']
};
...
Basically I can get the map to work great if I set the Long/Lat co-ordinates but instead I want these to be passed by getting the users location. With the code above the map is displaying on my phone but with the following error:
TypeError: 'undefined' is not an object (evaluating 'position.coords.latitude')
but on the desktop I get no map and the following error:
Uncaught TypeError: Cannot read property 'latitude' of undefined
Any help would be great I'm a newbie to Javascript and these APis
More From » html