Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在HTML/Javascript文件中获取App Inventor 2变量值_Javascript_Html_Google Maps_App Inventor - Fatal编程技术网

在HTML/Javascript文件中获取App Inventor 2变量值

在HTML/Javascript文件中获取App Inventor 2变量值,javascript,html,google-maps,app-inventor,Javascript,Html,Google Maps,App Inventor,我正在为用户设置一个简单的地图程序,让用户可以在嵌入式谷歌地图上查看位置。我有地图工作,但我想知道是否有一种方法让用户在AI2中输入坐标,然后让地图中心在那里。 这是我用来显示地图的HTML文件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1.0, user-scal

我正在为用户设置一个简单的地图程序,让用户可以在嵌入式谷歌地图上查看位置。我有地图工作,但我想知道是否有一种方法让用户在AI2中输入坐标,然后让地图中心在那里。 这是我用来显示地图的HTML文件

<!DOCTYPE html>
<html>
   <head>
     <meta charset="utf-8">
     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
     <style type="text/css">
     html { height: 100% }
     body { height: 100%; margin: 0; padding: 0 }
     #map_canvas { height: 100% }
     </style>

     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&sensor=true&language=en"></script>

     <script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-34.397, 150.644),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
     };
     map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    // Add a listener for the click event
    google.maps.event.addListener(map, 'click', showPosition);
  }

  function showPosition(event) {
    // display a marker on the map
    marker = new google.maps.Marker({
      position: event.latLng,
      map: map,
      icon: "./marker.png"
    });

    // print the selected position to the page title
    var position = event.latLng.lat().toFixed(6) + ", " + event.latLng.lng().toFixed(6);
    window.document.title = position;
  }
</script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>
是的,那是可能的

您可以使用WebViewString在应用程序和WebViewer之间来回传递值。在应用程序中,您可以获取并设置WebViewer.WebViewString属性。在webviewer中,使用其getWebViewString和setWebViewStringtext方法打开包含引用window.AppInventor对象的Javascript的页面

另请参见以下完整示例

<!doctype html>
<head>
  <meta name="author" content="puravidaapps.com">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Test</title>
</head>
<body>
  <script>
    document.write("The value from the app is<br />" + window.AppInventor.getWebViewString());
    window.AppInventor.setWebViewString("hello from Javascript")
  </script>
</body>
</html>

非常感谢。实际上我正在看你关于如何实现地图的页面。