0

我们如何使用

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

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

或者你可以帮助我使用像https://developers.google.com/maps/documentation/javascript/tutorial这样的 javascript api

我使用了它,但没有像之前的 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>

请提前帮助

4

2 回答 2

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>
于 2013-02-15T12:47:19.360 回答
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>

顺便说一句,我自己做的thanx

于 2013-02-15T10:47:40.707 回答