java - 如何通过 Android Studio 中的 WebView 实现 Google 地图
问题描述
我在将 Google 地图应用到我的应用时遇到了问题。使用普通的 API,我可以完美地完成它,直到我想进行搜索。它只是不加载。跨论坛阅读似乎需要 Google Cloud 上的结算帐户才能正常工作。这就是为什么我试图在某个 Activity 上实现一个 Google Maps WebView(显然,有一个正常工作的搜索栏)。我对 WebViews 一点也不熟悉,所以我会很感激对傻瓜的解释。提前致谢。
附带说明一下,我没有使用其他线程,因为大多数线程来自大约 5 年前,并且大部分代码已被弃用。
解决方案
I implemented on a Constraint Layout a normal Web View. It had the ID of "webView". The following code was used on the Activity itself
package com.example.donafelicidad;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ComedoresActivity2 extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comedores2);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.google.com/maps");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else{
super.onBackPressed();
}
}
}
It allows the map to work perfectly (implementation of JavaScript), while also allowing the user to return to a previous state on the Web View (implementation of onBackPressed).
推荐阅读
- python - 2个元组列表之间的可能排列(调度算法)
- javascript - Laravel Cashier - “此客户没有附加付款来源或默认付款方式。”
- python - 如何获得不能等于另一个值的随机值?
- c# - 在 Winforms 文本框 C# 上打印
- python - 如何将 JSON 根数组读入列表?
- json - 动态 json 的 Golang 结构,返回空值
- python - 阅读没有标题的列
- git - 分支之间的 Git 历史差异
- sas - 如何使用数据格式 DDMMYYDw。在 Proc Import SAS MACRO
- prettier - 当我不希望它时,更漂亮地格式化一个 Vue 组件