2011-03-02 54 views
0

我有一個web應用程序,它在Web視圖中顯示網頁。但網頁無法拿起getcurrentposition,但是如果我在android broswer中顯示它的網頁,但不是在web應用程序中?Android Web應用程序無法啓動GPS

當頁從一個Web應用程序運行時顯示該頁面的地圖顯示有 它會在下面的JS的「這裏」警報和 「錯誤:地理定位服務失敗。」

有沒有人寫過本地的網絡應用程序,可以拿起地理位置? java web應用程序或許可中必須有其他必需的東西。有沒有人做到了這一點..

這裏是我想要使用谷歌例如HTML,

http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html 這裏是JS

var initialLocation; 
var siberia = new google.maps.LatLng(60, 105); 
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687); 
var browserSupportFlag = new Boolean(); 
var map; 
var infowindow = new google.maps.InfoWindow(); 

function initialize() { 
    var myOptions = { 
     zoom: 6, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    // Try W3C Geolocation method (Preferred) 
    if (navigator.geolocation) { 
     browserSupportFlag = true; 
     alert('here navigator'); 
     navigator.geolocation.getCurrentPosition(function (position) { 
      initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
      contentString = "Location found using W3C standard"; 
      map.setCenter(initialLocation); 
      infowindow.setContent(contentString); 
      infowindow.setPosition(initialLocation); 
      infowindow.open(map); 
     }, function() { 
      handleNoGeolocation(browserSupportFlag); 
     }); 
    } else if (google.gears) { 
     // Try Google Gears Geolocation 
     browserSupportFlag = true; 
     var geo = google.gears.factory.create('beta.geolocation'); 
     geo.getCurrentPosition(function (position) { 
      initialLocation = new google.maps.LatLng(position.latitude, position.longitude); 
      contentString = "Location found using Google Gears"; 
      map.setCenter(initialLocation); 
      infowindow.setContent(contentString); 
      infowindow.setPosition(initialLocation); 
      infowindow.open(map); 
     }, function() { 
      handleNoGeolocation(browserSupportFlag); 
     }); 
    } else { 
     // Browser doesn't support Geolocation 
     browserSupportFlag = false; 
     handleNoGeolocation(browserSupportFlag); 
    } 
} 

function handleNoGeolocation(errorFlag) { 
    if (errorFlag == true) { 
     initialLocation = newyork; 
     contentString = "Error: The Geolocation service failed."; 
    } else { 
     initialLocation = siberia; 
     contentString = "Error: Your browser doesn't support geolocation. Are you in Siberia?"; 
    } 
    map.setCenter(initialLocation); 
    infowindow.setContent(contentString); 
    infowindow.setPosition(initialLocation); 
    infowindow.open(map); 
} 

任何想法.. 感謝邁克

+0

你想做什麼?我從來沒有聽說過原生的網絡應用程序。我假定你的意思是你製作了一個Android應用程序,只顯示你的網頁應用程序的頁面? – 2011-04-11 13:34:22

+0

是的,你是正確的一個Android應用程序,顯示一個網站地理位置.. – ozmike 2011-07-05 13:40:37

回答

0

是的,它得到它的工作。但是我在js中編寫了自己的導航器對象,並通過jsinterface連接到了java。基本上我首先在非網絡應用程序中使用GPS。然後在java中寫了一個java腳本接口。然後從js中調用java中的jsinterface來獲取地理位置。我的方法的好處是它應該在1.5以上工作,它在仿真器上工作。壞消息是它需要編碼的負擔。這種方法將工作,但不幸的是在2.3的JavaScript界面​​不是很穩定 - 其他版本的Android都可以。