0

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..

4

3 回答 3

1

你的错误:var coords = new YGeoPoint(latitude,Longitude);

经度不是带大写“L”的经度

那么工作正常!

于 2012-05-17T02:30:25.330 回答
0

它工作正常。基本上有时它有效,而另一些则无效。我不知道为什么,但代码工作正常。

于 2012-05-18T14:50:45.787 回答
0

我使用“new Y.Map()”而不是“new YMap()”。也许效果相同。

于 2020-03-24T05:14:16.347 回答