谷歌地图显示位置,如https://maps.google.com/maps?q=loc:28.617885999999999,77.372363000000007

时间:2013-02-15 10:21:00

标签: javascript google-maps iframe google-maps-api-3

我们如何使用

https://maps.google.com/maps?q=loc:28.617885999999999,77.372363000000007

直接在html中使用iframe或其他东西。我也想要显示位置,就像它在其中显示A

或者你可以帮我使用javascript api,如https://developers.google.com/maps/documentation/javascript/tutorial

我使用过它,但没有在之前的

中显示像A这样的位置标记
<!DOCTYPE html>
<html>
  <head>
    <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?key=YOUR_API_KEY&sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(28.617885999999999, 77.372363000000007),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>

请提前帮助

2 个答案:

答案 0 :(得分:1)

不使用地理编码器:

<!DOCTYPE html>
<html>
  <head>
    <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=false">
    </script>
    <script type="text/javascript">

  var map;
  function initialize() {
    var Lat = 28.617885999999999;
    var Long = 77.372363000000007;
    var latlng = new google.maps.LatLng(Lat, Long);
    var mapOptions = {
      zoom: 12,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    var marker = new google.maps.Marker({
        map: map,
        position: latlng
    });
  }

    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width: 100%; height: 100%;"></div>
  </body>
</html>

答案 1 :(得分:0)

<!DOCTYPE html>
<html>
  <head>
    <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=false">
    </script>
    <script type="text/javascript">
      var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var Lat = 28.617885999999999;
    var Long = 77.372363000000007;
    var latlng = new google.maps.LatLng(Lat, Long);
    var mapOptions = {
      zoom: 12,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var address = Lat+', '+Long;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Sorry no recent location");
      }
    });
  }

    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width: 100%; height: 100%;"></div>
  </body>
</html>

顺便说一下,用自己的自我来做这件事