Google Maps Embeded:将iFrame转换为iOS / Android中的链接

Google Maps Embed: Turn iFrame into a link in iOS/Android

本文关键字:iOS Android 链接 转换 Embeded Maps iFrame Google      更新时间:2023-09-26

在我的网站上,我有一个嵌入式谷歌地图,指向我的公司所在地。当有人在 iOS/Android 设备上查看我的网站时,我希望他们能够点击地图,并使用 URL 架构在原生 Google 地图应用程序中打开地图

comgooglemaps://

我的计划是将iFrame变成这些设备上的链接,但我没有运气。

任何人都知道如何执行此操作或对如何实现此功能有更好的想法。

我有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",

当将其解析为字符串时,....结果

字符串 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 宽度=600 高度=450 框架边框=0 样式=边框: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 类:主活动

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");
    }
}

安卓清单.xml

  1. <uses-permission android:name="android.permission.INTERNET"/>

还有 chek WIFI 权限等。

我决定冒险我的方法,当浏览器低于一定大小时,我使用 jQuery 隐藏 iFrame 并将其替换为静态图像。那时我是一件简单的事情。