小编use*_*726的帖子

Google地图会对字符串进行地理编码

我刚接触谷歌地图api并完成了地理编码示例:

https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple

我希望能够在我的代码中对字符串进行地理编码,并在该位置放置标记,而不是用户搜索位置.到目前为止我的代码是:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Geocoding service</title>
    <style>
      html, body, #map-canvas 
      {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
   //global variables 
var geocoder;
var map;
var Ireland = "Dublin";

function initialize() 
{
  geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(53.3496, -6.3263);
  var mapOptions = 
  {
    zoom: 8,
    center: latlng
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  codeAddress();//call the function
}

function codeAddress() 
{
  var address = document.getElementById("Ireland").value;
  geocoder.geocode( …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps geocoding google-maps-api-3

6
推荐指数
2
解决办法
5万
查看次数