【问题标题】:Google Maps Embed: Turn iFrame into a link in iOS/AndroidGoogle Maps Embed:将 iFrame 变成 iOS/Android 中的链接
【发布时间】:2017-06-21 14:04:17
【问题描述】:
在我的网站上,我有一个嵌入的 Google 地图,指向我的业务位置。当有人在 iOS/Android 设备上查看我的网站时,我希望他们能够点击地图并使用 URL 架构在本地 Google 地图应用程序中打开它
comgooglemaps://
我的计划是将 iFrame 变成这些设备上的链接,但我没有运气。
任何人都知道如何执行此操作,或者对如何实现此功能有更好的了解。
【问题讨论】:
标签:
javascript
jquery
html
ios
google-maps
【解决方案1】:
我有 JSON
"GoogleMap":"\u003ciframe src=\"https://www.google.com/maps/embed?pb=!1m16!1m12!1m3!1d434549.40374533384!2d74.24349628287739!3d31.690830957117996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!2m1!1sPakistan+Lahore!5e0!3m2!1sen!2s!4v1395138949280\" width=\"600\" height=\"450\" frameborder=\"0\" style=\"border:0\"\ u003e\u003c/iframe\u003e",
解析为String时,...结果
String iframe = "https://www.google.com/maps/embed?pb=!1m16!1m12!1m3!1d434549.40374533384!2d74.24349628287739!3d31.690830957117996!2m3!1f0!2f0!3f0! 3m2!1i1024!2i768!4f13.1!2m1!1sPakistan+Lahore!5e0!3m2!1sen!2s!4v1395138949280 width=600 height=450 frameborder=0 style=border:0";
布局:activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#00FF00" >
<TextView
android:id="@+id/header_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Google Map"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
<WebView
android:id="@+id/googlemap_webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" />
</LinearLayout>
Java 类:MainActivity
public class MainActivity extends Activity {
private WebView googleMapWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeUI();
}
/**
* This method is used to Initialize UI components
*/
private void initializeUI() {
String iframe = "<iframe src=https://www.google.com/maps/embed?pb=!1m16!1m12!1m3!1d434549.40374533384!2d74.24349628287739!3d31.690830957117996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!2m1!1sPakistan+Lahore!5e0!3m2!1sen!2s!4v1395138949280 width=600 height=450 frameborder=0 style=border:0</iframe>";
googleMapWebView = (WebView) findViewById(R.id.googlemap_webView);
googleMapWebView.getSettings().setJavaScriptEnabled(true);
googleMapWebView.loadData(iframe, "text/html", "utf-8");
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
还检查 WIFI 权限等 ..
【解决方案2】:
我决定尝试我的方法,当浏览器小于某个特定大小时,我使用 jQuery 隐藏 iFrame 并将其替换为静态图像。那时我是一件简单的事情。