javascript - 从 Google map 加载 div 中的确切位置

标签 javascript

我对在我的网站中使用 Google map 的概念相当陌生。我已经使用此脚本来加载网页中 div 中的特定位置。但是,所需的位置未加载到我的页面中。

<小时/>

假设,每当我们打开页面时,我想在 div 中加载位置 BIT Main Bldg Patna, Bihar, India 12 m E。但是,结果并不准确,我们需要再放大几层。

<小时/>
<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps Geocoding Demo</title> 
   <script src="http://maps.google.com/maps/api/js?sensor=false" 
           type="text/javascript"></script> 
</head> 
<body> 
   <div id="map" style="width: 400px; height: 300px;"></div> 

   <script type="text/javascript"> 

   var address = 'BIT Main Bldg Patna, Bihar, India 12 m E';

   var map = new google.maps.Map(document.getElementById('map'), { 
       mapTypeId: google.maps.MapTypeId.TERRAIN,
       zoom: 8
   });

   var geocoder = new google.maps.Geocoder();

   geocoder.geocode({
      'address': address
   }, 
   function(results, status) {
      if(status == google.maps.GeocoderStatus.OK) {
         new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
         });
         map.setCenter(results[0].geometry.location);
      }
      else {
         // Google couldn't geocode this request. Handle appropriately.
      }
   });

   </script> 
</body> 
</html>
<小时/>

您可以通过在 this 的输出文本框中输入 BIT Main Bldg Patna, Bihar, India 12 m E 来看到确切的期望结果。页。这里有什么错误?

最佳答案

要使您的页面显示与您链接到的页面上的 map 类似的 map ,您需要更改在 map 构造函数中提供的选项。将 zoom 属性更改为 15 或 16,并将 mapTypeId 更改为 google.maps.MapTypeId.ROADMAP,您的 map 将看起来更像您的 map 铭记于心。

关于javascript - 从 Google map 加载 div 中的确切位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13549881/

相关文章:

javascript - 我的 javascript 示例存在一些问题。请帮忙

javascript - 何时访问属性(相对于属性)?

javascript - 文本/javascript 与应用程序/javascript

javascript - javascript中的字符串操作

javascript - 从 textarea 复制到 div,保留换行符

javascript - 首次访问站点时只需要执行一次查询

javascript - 在字符串中查找数组中所有出现的元素

javascript - 不支持 svg 的浏览器的 CSS hack

javascript - AngularJS ng-include 作用域

javascript - 带 SVG 的 Tabby JS 防止滚动