java - 获取 GPS 位置时,加载另一个 URL

标签 java android gps android-webview

我有一个小问题...我制作了一个扩展 webview 的 Android 应用程序。带有 map 的 webview Html 页面如下所示:Map example ,也是在这里我得到了灵感。我的 onCreate 方法如下所示:

super.onCreate(savedInstanceState);

         //Removes the title bar in the application
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.main);
         
         //Creation of the Webview found in the XML Layout file
         browserView = (WebView)findViewById(R.id.webkit);

         //Removes both vertical and horizontal scroll bars 
         browserView.setVerticalScrollBarEnabled(false);
         browserView.setHorizontalScrollBarEnabled(false);
         
        
         myLocationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
         //Enable Javascripts
      
         url = "http://www.my-homepage.dk/map_example.html";
         
         browserView.getSettings().setJavaScriptEnabled(true);

         
         //The website which is wrapped to the webview
        
         browserView.loadUrl(url);

因此,当我的应用程序获取 GPS 位置时,它会调用此方法:

LocationListener onLocationChange=new LocationListener() {
 
 
  public void onLocationChanged(Location location) {
 
 
 StringBuilder buf=new StringBuilder(url);
 
 buf.append("?");
 buf.append("lon=");
 buf.append(String.valueOf(location.getLongitude()));
 buf.append("&");
 buf.append("lat=");
 buf.append(String.valueOf(location.getLatitude()));
     
    browserView.loadUrl(buf.toString());
 
 }

所以它基本上只是加载另一个网址......但是,我的问题是,1.它保留原始网站“ map 图像”,我想它会“卸载”页面,2.当第二个网址是加载后,需要相当长的时间才能完成,当我在 HTC Desire 上测试时,有时在关闭屏幕和锁定之前不显示第二个加载的页面(带有位置的 map ),或者如果我去在应用程序中和外部,有时这也有帮助......

希望能帮到你:)

最佳答案

建议 - 在 onLocationChanged 中,将 locationFound(); 作为第一个语句而不是最后一个语句。

最好立即停止监听器,因为 loadUrl 语句可能需要一些时间才能完成,而提供程序可能会发送更多更新。

关于java - 获取 GPS 位置时,加载另一个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3767155/

相关文章:

java - 如何调度 Java 线程

Java ZonedDateTime 到即时转换

android - 纹理仅显示为黑色

android - 在应用程序之间使用隐式 Intent 的自定义操作

swift - 如何在Swift中为图像添加GPS位置

java - 与另一个 Android Activity 共享 LocationListener

java - 在 Java 中使用 Jericho HTML 解析器检索格式良好的 HTML

java - 从 groovy 类中的应用程序上下文获取 spring bean

java - Android 设备监视器失败,并显示“解析输入时出现意外错误 : Invalid uiautomator hierarchy file”

android - 获得 10 米精度 GPS 定位的合理时间是多少?