2013-11-14 67 views
-1

我如何從座標的經度,緯度獲取地點類型?如何從谷歌地圖中的座標(拉特,longt)獲取地點類型

當我讀下面的url時,它可以做到。但在這裏我無法傳遞座標作爲輸入(對於變量名稱功能)。請任何人指導我如何做。

https://developers.google.com/maps/tutorials/customizing/custom-markers

var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/'; 
var icons = { 
    parking: { 
    icon: iconBase + 'parking_lot_maps.png' 
    }, 
    library: { 
    icon: iconBase + 'library_maps.png' 
    }, 
    info: { 
    icon: iconBase + 'info-i_maps.png' 
    } 
}; 

function addMarker(feature) { 
    var marker = new google.maps.Marker({ 
    position: feature.position, 
    icon: icons[feature.type].icon, 
    map: map 
    }); 
} 

我的要求是,以顯示在谷歌協調與自身的icon.It意味着,如果座標屬於醫院的話,我應該表現出醫院圖標....喜歡這種方式。

所以如果我從它的座標知道地點類型,那麼我認爲它可以做到。

  1. 也可以任何人給我地點類型和它的形象的映射。

謝謝...

+0

「功能」來自哪裏(在「addMarker(功能){...」)中,在[該教程]的源代碼中(https://google-developers.appspot.com/maps/tutorials/customizing/js/markers)有一個包含這些特徵的數組。 – geocodezip

+0

Plz閱讀URL並告訴我。 https://developers.google.com/maps/tutorials/customizing/custom-markers。我知道它的代碼。 – TATAS

回答

0

是的,你真的可以做到這一點。

我不知道這是否是最佳解決方案。如果您有座標(經度,緯度),請將這些座標通過您自己的API密鑰傳遞給此Google PALCE API。

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

API關鍵是自己的Google PLACE API KEY

只看此JSON響應: -

{ 
    "html_attributions" : [ 
    "Listings by \u003ca href=\"http://www.yellowpages.com.au/\"\u003eYellow  Pages\u003c/a\u003e" 
    ], 
"results" : [ 
    { 
    "formatted_address" : "529 Kent Street, Sydney NSW, Australia", 
    "geometry" : { 
     "location" : { 
      "lat" : -33.8750460, 
      "lng" : 151.2052720 
     } 
    }, 
    "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png", 
    "id" : "827f1ac561d72ec25897df088199315f7cbbc8ed", 
    "name" : "Tetsuya's", 
    "rating" : 4.30, 
    "reference" : "CnRmAAAAmmm3dlSVT3E7rIvwQ0lHBA4sayvxWEc4nZaXSSjRtfKRGoYnfr3d5AvQGk4e0u3oOErXsIJwtd3Wck1Onyw6pCzr8swW4E7dZ6wP4dV6AsXPvodwdVyqHgyGE_K8DqSp5McW_nFcci_-1jXb5Phv-RIQTzv5BjIGS0ufgTslfC6dqBoU7tw8NKUDHg28bPJlL0vGVWVgbTg", 
    "types" : [ "restaurant", "food", "establishment" ] 
    }, 
    { 
    "formatted_address" : "Upper Level, Overseas Passenger Terminal/5 Hickson Road, The Rocks NSW, Australia", 
    "geometry" : { 
     "location" : { 
      "lat" : -33.8583790, 
      "lng" : 151.2100270 
     } 
    }, 
    "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png", 
    "id" : "f181b872b9bc680c8966df3e5770ae9839115440", 
    "name" : "Quay", 
    "rating" : 4.10, 
    "reference" : "CnRiAAAADmPDOkn3znv_fX78Ma6X5_t7caEGNdSWnpwMIdDNZkLpVKPnQJXP1ghlySO-ixqs28UtDmJaOlCHn18pxpj7UQjRzR4Kmye6Gijoqoox9bpkaCAJatbJGZEIIUwRbTNIE_L2jGo5BDqiosqU2F5QdBIQbXKrvfQuo6rmu8285j7bDBoUrGrN4r6XQ-PVm260PFt5kwc3EfY", 
    "types" : [ "cafe", "bar", "restaurant", "food", "establishment" ] 
    }, 
    { 
    "formatted_address" : "107 George Street, The Rocks NSW, Australia", 
    "geometry" : { 
     "location" : { 
      "lat" : -33.8597750, 
      "lng" : 151.2085920 
     } 
    }, 
    "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png", 
    "id" : "7beacea28938ae42bcac04faf79a607bf84409e6", 
    "name" : "Rockpool", 
    "rating" : 4.0, 
    "reference" : "CnRlAAAAVK4Ek78r9yHV56I-zbaTxo9YiroCbTlel-ZRj2i6yGAkLwNMm_flMhCl3j8ZHN-jJyG1TvKqBBnKQS2z4Tceu-1kZupZ1HSo5JWRBKd7qt2vKgT8VauiEBQL-zJiKVzSy5rFfilKDLSiLusmdi88ThIQqqj6hKHn5awdj6C4f59ifRoUg67KlbpuGuuW7S1tAH_EyBl6KE4", 
    "types" : [ "restaurant", "food", "establishment" ] 
    }, 
    { 
    "formatted_address" : "483 George Street, Sydney NSW, Australia", 
    "events" : [ 
     { 
      "event_id" : "7lH_gK1GphU", 
      "summary" : "Google Maps Developer Meetup: Rockin' out with the Places API", 
      "url" : "https://developers.google.com/places" 
     } 
     ], 
    "geometry" : { 
     "location" : { 
      "lat" : -33.8731950, 
      "lng" : 151.2063380 
     } 
    }, 
    "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/civic_building-71.png", 
    "id" : "017049cb4e82412aaf0efbde890e82b7f2987c16", 
    "name" : "Chinatown Sydney", 
    "rating" : 4.0, 
    "reference" : "CnRuAAAAsLNeRQtKD7TEUXWG6gYD7ByOVKjQE61GSyeGZrX-pOPVps2BaLBlH0zBHlrVU9DKhsuXra075loWmZUCbczKDPdCaP9FVJXB2NsZ1q7188pqRFik58S9Z1lcWjyVoVqvdUUt9bDMLqxVT4ENmolbgBIQ9Wy0sgDy0BgWyg5kfPMHCxoUOvmhfKC-lTefXGgnsRqEQwn8M0I", 
    "types" : [ 
     "city_hall", 
     "park", 
     "restaurant", 
     "doctor", 
     "train_station", 
     "local_government_office", 
     "food", 
     "health", 
     "establishment" 
    ] 
    } 
    ], 
    "status" : "OK" 
} 

然後讓你的地方的圖標: -

"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png", 

for mor閱讀original link