0

店舗検索を作成しています。ユーザーがその場所を入力するための最良の方法は何ですか。ユーザー入力を緯度と経度に変換する方法が必要です。

ユーザーが何かを入力して緯度と経度に変換するにはどうすればよいですか。

ありがとう

4

2 に答える 2

2

まず、ページの読み込み時に初期化コードを含めます。

var myOptions = {
  zoom: 13,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

onclick 属性またはフォームの送信を使用して関数をトリガーします。

次に、トリガーする関数でこれをドロップします(注:これはjQueryを使用します):

var address = $('#name_of_input_box').val();

次に、Google Geocoder API を使用して、テキスト ボックス内の住所をジオコーディングします。

var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function (result, status) {
  cur_lng = result[0].geometry.location.lng();
  cur_lat = result[0].geometry.location.lat();
  var location = new google.maps.LatLng(cur_lat, cur_lng);
});

map.setCenter(location);
于 2012-07-26T17:27:50.977 に答える
1

ジオコーダーを使用する必要があります。以下のこのリンクを参照してください

API V3 を使用するには https://developers.google.com/maps/documentation/javascript/reference#Geocoder

WebService を使用するには https://developers.google.com/maps/documentation/geocoding/index

それについて助けが必要な場合は、もう一度質問してください

よろしく cadetill

于 2012-07-26T09:28:38.227 に答える