2015-11-25 78 views
0

是否可以使用关键字设置标记的位置。Gmaps按名称设置标记位置

由于设置标记的位置的常规方式是这样的:

GMarkerGoogle marker = new GMarkerGoogle(new GMap.NET.PointLatLng("47.101343, 2.707210"), GMarkerGoogleType.green); 

但我不希望设置使用坐标位置。

它可以设置像这样的关键字gmapControl位置:

gMapControl1.SetPositionByKeywords("Weert, Netherlands"); 

但定位标记时,是这样也可以?

回答

0

使用地理编码,以实现自己的目标(通常指文件修道院):https://developers.google.com/maps/documentation/javascript/geocoding

小提琴例子(写你在搜索框中输入地址):http://jsfiddle.net/ackzell/t0e7fma0/

代码示例(JS):

function codeAddress() 
{ 
    var address = document.getElementById("address").value; 
    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("Geocode was not successful for the following reason: " + status); 
     } 
    }); 
}