タグ:Google Maps
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=【取得したAPIキー】&libraries=places" charset="utf-8"></script>
<input type="text" size="55" id="search" value="池袋駅付近のカフェ" /> <input type="button" size="55" value="検索" onClick="SearchGo()" /> <div id="map_canvas" style="width: 100%; height: 90%;"></div>
var mayMap;
var service;
// マップの初期設定
function initialize() {
// Mapクラスのインスタンスを作成(緯度経度は池袋駅に設定)
var initPos = new google.maps.LatLng(35.729756, 139.711069);
// 地図のプロパティを設定(倍率、マーカー表示位置、地図の種類)
var myOptions = {
zoom: 15,
center: initPos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// #map_canva要素にMapクラスの新しいインスタンスを作成
myMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// 検索の条件を指定(緯度経度、半径、検索の分類)
var request = {
location: initPos,
radius: 1000, // ※1 表示する半径領域を設定(1 = 1M)
types: ['cafe'] // ※2 typesプロパティの施設タイプを設定
};
var service = new google.maps.places.PlacesService(myMap);
service.search(request, Result_Places);
}
// 検索結果を受け取る
function Result_Places(results, status){
// Placesが検家に成功したかとマうかをチェック
if(status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
// 検索結果の数だけ反復処理を変数placeに格納
var place = results[i];
createMarker({
text : place.name,
position : place.geometry.location
});
}
}
}
// 入力キーワードと表示範囲を設定
function SearchGo() {
var initPos = new google.maps.LatLng(0,0);
var mapOptions = {
center : initPos,
zoom: 0,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
// #map_canva要素にMapクラスの新しいインスタンスを作成
myMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
service = new google.maps.places.PlacesService(myMap);
// input要素に入力されたキーワードを検索の条件に設定
var myword = document.getElementById("search");
var request = {
query : myword.value,
radius : 5000,
location : myMap.getCenter()
};
service.textSearch(request, result_search);
}
// 検索の結果を受け取る
function result_search(results, status) {
var bounds = new google.maps.LatLngBounds();
for(var i = 0; i < results.length; i++){
createMarker({
position : results[i].geometry.location,
text : results[i].name,
map : myMap
});
bounds.extend(results[i].geometry.location);
}
myMap.fitBounds(bounds);
}
// 該当する位置にマーカーを表示
function createMarker(options) {
// マップ情報を保持しているmyMapオブジェクトを指定
options.map = myMap;
// Markcrクラスのオブジェクトmarkerを作成
var marker = new google.maps.Marker(options);
// 各施設の吹き出し(情報ウインドウ)に表示させる処理
var infoWnd = new google.maps.InfoWindow();
infoWnd.setContent(options.text);
// addListenerメソッドを使ってイベントリスナーを登録
google.maps.event.addListener(marker, 'click', function(){
infoWnd.open(myMap, marker);
});
return marker;
}
// ページ読み込み完了後、Googleマップを表示
google.maps.event.addDomListener(window, 'load', initialize);
types:['bank', 'dentist', ・・・]
| accounting | 事務所 |
|---|---|
| airport | 空港 |
| amusement_park | 遊園地 |
| art_gallery | 美術館 |
| atm | ATM |
| bakery | パン屋 |
| bank | 銀行 |
| bar | バー |
| beauty_salon | 美容室・ネイルサロン |
| bicycle_store | 自転車屋 |
| bowling_alley | ボウリング場 |
| bus_station | バス停 |
| cafe | カフェ |
| campground | キャンプ場 |
| car_dealer | 自動車ディーラー |
| car_rental | レンタカー屋 |
| car_repair | 自動車修理 |
| car_wash | 洗車場 |
| casino | カジノ |
| cemetery | 墓地 |
| church | 教会 |
| city_hall | 市役所 |
| clothing_store | 洋服店 |
| clothing_store | コンビニ |
| courthouse | 裁判所 |
| dentist | 歯科 |
| department_store | デパート |
| doctor | 医者 |
| electrician | 電気事業者 |
| electronics_store | 電器屋 |
| embassy | 大使館 |
| establishment | 詳細不明 |
| finance | 財務機関 |
| fire_station | 消防署 |
| florist | 花屋 |
| food | 飲食店 |
| funeral_home | 斎場 |
| furniture_store | 家具屋 |
| gas_station | ガソリンスタンド |
| general_contractor | ゼネコン |
| grocery_or_supermarket | 日用品店・スーパーマーケット |
| gym | スポーツジム |
| hair_care | 床屋 |
| hardware_store | 工具店, ホームセンター |
| health | 主に医療機関 |
| hindu_temple | ヒンドゥー寺院 |
| home_goods_store | ホームセンター |
| hospital | 医療機関・クリニック |
| insurance_agency | 保険代理店 |
| jewelry_store | 宝石店 |
| laundry | クリーニング店・コインランドリー |
| lawyer | 法律事務所 |
| library | 図書館 |
| liquor_store | 酒店 |
| local_government_office | 地方公共団体 |
| locksmith | 鍵屋 |
| lodging | 宿泊施設 |
| meal_delivery | 飲食店(出前系) |
| meal_takeaway | 飲食店(テイクアウト系) |
| mosque | イスラム教の礼拝堂 |
| movie_rental | レンタルビデオ店 |
| movie_theater | 映画館 |
| moving_company | 運送屋・引越し屋 |
| museum | 博物館・ミュージアム |
| night_club | ナイトクラブ |
| painter | 塗装屋 |
| park | 公園 |
| parking | 駐車場 |
| pet_store | ペット屋 |
| pharmacy | 薬局 |
| physiotherapist | 療法士 |
| place_of_worship | 神社・寺 |
| plumber | 配管工・水道業者 |
| police | 警察署・交番 |
| post_office | 郵便局 |
| real_estate_agency | 不動産業者 |
| restaurant | レストラン |
| roofing_contractor | 屋根修理 |
| rv_park | 車中泊ができる施設 |
| school | 学校・塾 |
| shoe_store | 靴屋 |
| shopping_mall | ショッピングモール |
| spa | 温泉・銭湯 |
| stadium | スタジアム |
| storage | 倉庫 |
| store | 店(※かなり曖昧で精度は低い) |
| subway_station | 鉄道駅(地下鉄のみ) |
| synagogue | ユダヤ教の会堂 |
| taxi_stand | タクシー乗り場 |
| train_station | 鉄道駅 |
| travel_agency | 旅行代理店 |
| university | 大学 |
| veterinary_care | 動物病院 |
| zoo | 動物園 |
