Question

i'm trying to get coordinates from geolocation for use in my yahoo map.i had run it in firefox, chrome and internet explorer version 12.0, 18.0.1025.168 m and 9.0.8112.16421. In firefox it asks for permission to share my location(i accept), internet explorer it doesn't support geolocation and chrome supports its but not find the location. here is my code

<div id="map" align="right" height="50%" width="50%"> </div>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=xoo5uJLV34FTpTmoqrs.mIQOX_DTcBhPowcz17ClEeb.jCIZ1Z6_Aa9FO8brGg--"></script>
<script type="text/javascript">

alert("ok ws dame");
if(navigator.geolocation) {
    alert("Great..Geolocation API is supported.");
    var map = new YMap(document.getElementById('map')); 
    map.addTypeControl(); 
    map.setMapType(YAHOO_MAP_REG);

    navigator.geolocation.getCurrentPosition(foundlocation,nolocation);

    function foundlocation(position){
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    alert(latitude+","+longitude);
    var coords = new YGeoPoint(latitude,Longitude);
    map.drawZoomAndCenter(coords,3);
    map.addMarker(coords);
    }
    function nolocation(error){
var map = new YMap(document.getElementById('map')); 
map.addTypeControl(); 
map.setMapType(YAHOO_MAP_REG);
    alert("Location not found.");
    // Display the map centered on a geocoded location
    map.drawZoomAndCenter("Patras", 3);
    var Lat = 38.2444444;
    var Lon = 21.7344444;
    var myPoint = new YGeoPoint(Lat,Lon);
    map.addMarker(myPoint);     
    }
}
else {
var map = new YMap(document.getElementById('map')); 
map.addTypeControl(); 
map.setMapType(YAHOO_MAP_REG);
    alert("Geolocation API is not supported in your browser.");
    // Display the map centered on a geocoded location
    map.drawZoomAndCenter("Patras", 3);
    var Lat = 38.2444444;
    var Lon = 21.7344444;
    var myPoint = new YGeoPoint(Lat,Lon);
    map.addMarker(myPoint);
}
</script>

in case of (navigator.geolocation) returns false then it shows corectly the deafault position on the map.This works the same in function(nolocation). My problem is when i get the current location.I had put alert messages under navigator.geolocation.getCurrentPosition(foundlocation,nolocation); and inside function(foundlocation) it never shows the message. any help appreciate..

Was it helpful?

Solution 2

it works fine. basicly sometimes it works and some others it doesnt. i dont know why but the code works fine.

OTHER TIPS

your error:var coords = new YGeoPoint(latitude,Longitude);

longitude NOT Longitude with Uppercase "L"

works fine then!!

I use the "new Y.Map()" instead of "new YMap()".Maybe the same effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top