如何使用谷歌地图? [英] How to use google Maps?

查看:98
本文介绍了如何使用谷歌地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得谷歌地图的图像,其中SW角落在北纬10和东经0,东北角在58纬度和60经度?

所有我需要的只是一张地图的图片,通过谷歌地图获得,并在这些点进行结算。



任何帮助表示赞赏。谢谢。

解决方案

 < script type =text / javascript> 
函数initialize(){
var mapOptions = {
center:new google.maps.LatLng(58,60),
zoom:13,
mapTypeId:google .maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);

autocomplete.bindTo('bounds',map);

var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map:map
});

google.maps.event.addListener(autocomplete,'place_changed',function(){
infowindow.close();
var place = autocomplete.getPlace();
if(place.geometry.viewport){
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); //为什么是17?因为它看起来不错。
}

var image = new google.maps.MarkerImage(
place.icon ,
new google.maps.Size(71,71),
new google.maps.Point(0,0),
google.maps.Point(17,34),
new google.maps.Size(35,35));
marker.setIcon(image);
marker.setPosition(place.geometry.location);

var address ='';
if(place.address_components){
address = [(place.address_components [0]&&
place.address_components [0] .short_name ||' '),
(place.address_components [1]&&
place.address_components [1] .short_name || ''),
(place.address_components [2]&&
place.address_components [2] .short_name ||'')
] .join('');
}

infowindow.setContent('< div>< strong>'+ place.name +'< / strong>< br>'+ address);
infowindow.open(map,marker);
});
}
google.maps.event.addDomListener(window,'load',initialize);
< / script>

并且定义了类似于...的HTML HTML组件。



< input id =searchTextFieldtype =textsize =50>
< div id =map_canvas>< / div>



将以下行标题添加到标题..
< script src =// maps.googleapis.com/maps/api/js?sensor=false&libraries=places
type =text / javascript> < / script>



它可以作为你的魔法...



好运

How could I obtain an image of google maps which has SW corner at latitude 10 and longitude 0, and NE corner at 58 latitude and 60 longitude?

All I need is just an image of the map obtained with google maps and settled at those points.

Any help is appreciated. Thank you.

解决方案

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

    var input = document.getElementById('searchTextField');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.bindTo('bounds', map);

    var infowindow = new google.maps.InfoWindow();
    var marker = new google.maps.Marker({
      map: map
    });

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infowindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);  // Why 17? Because it looks good.
      }

      var image = new google.maps.MarkerImage(
          place.icon,
          new google.maps.Size(71, 71),
          new google.maps.Point(0, 0),
          new google.maps.Point(17, 34),
          new google.maps.Size(35, 35));
      marker.setIcon(image);
      marker.setPosition(place.geometry.location);

      var address = '';
      if (place.address_components) {
        address = [(place.address_components[0] &&
                    place.address_components[0].short_name || ''),
                   (place.address_components[1] &&
                    place.address_components[1].short_name || ''),
                   (place.address_components[2] &&
                    place.address_components[2].short_name || '')
                  ].join(' ');
      }

      infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
      infowindow.open(map, marker);
    });
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

and ur define ur HTML components similar to...

<input id="searchTextField" type="text" size="50"> <div id="map_canvas"></div>

add following line line to header.. <script src="//maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>

It will work for u as a magic...

Good Luck

这篇关于如何使用谷歌地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆