Javascript 此处映射API-基本位置显示(placeId)
我使用JavaScript API在web页面上实现了地图,现在我想显示一些位置的基本信息。在JavaScriptAPI文档中,我在PlacesComponents部分找到了一个称为“基本位置显示”的部分,但有一个示例说明了如何使用placeId呈现信息 如果可能的话,我需要能够使用位置坐标检索信息。我尝试使用PHP代码来显示信息,该代码定义了地图上某个位置的坐标,而不是使用placeId,但它不起作用 这是我使用的一个代码示例:Javascript 此处映射API-基本位置显示(placeId),javascript,api,here-api,Javascript,Api,Here Api,我使用JavaScript API在web页面上实现了地图,现在我想显示一些位置的基本信息。在JavaScriptAPI文档中,我在PlacesComponents部分找到了一个称为“基本位置显示”的部分,但有一个示例说明了如何使用placeId呈现信息 如果可能的话,我需要能够使用位置坐标检索信息。我尝试使用PHP代码来显示信息,该代码定义了地图上某个位置的坐标,而不是使用placeId,但它不起作用 这是我使用的一个代码示例: var basicPlace = new nokia.place
var basicPlace = new nokia.places.widgets.Place({
placeId: PHP code instead of placeId.
*exp: [<?php code;?>, <?php echo code;?>],*
targetNode: "map",
template: "nokia.blue.place"
});
var basicPlace=new nokia.places.widgets.Place({
placeId:PHP代码而不是placeId。
*exp:[,]*
targetNode:“映射”,
模板:“nokia.blue.place”
});
有没有可能解决这样的问题,或者有一种方法不涉及placeId
链接:,如果您阅读诺基亚.places.widgets.Place,您将看到placeId是一个必需的参数。它实际上是此处保存的位置信息的主键。因此,您需要在显示之前使用JavaScript API发出另一个请求,以获取placeId,从而显示您的位置详细信息。这里要做的显而易见的事情是首先发出一个类别请求,并将placeId与每个标记一起存储,如下所示:
// Function for receiving search results from places search and process them
var processResults = function (data, requestStatus, requestId) {
var i, len, locations, marker;
if (requestStatus == "OK") {
locations = data.results ? data.results.items : [data.location];
if (locations.length > 0) {
for (i = 0, len = locations.length; i < len; i++) {
// Add a marker and store the placeId
marker = new nokia.maps.map.StandardMarker(locations[i].position,
{ text: i+1 ,
placeId : locations[i].placeId});
resultSet.objects.add(marker);
}
}
});
// etc.. etc...
//用于从搜索地点接收搜索结果并对其进行处理的函数
var processResults=函数(数据、请求状态、请求ID){
变量i、len、位置、标记;
如果(请求状态=“确定”){
位置=data.results?data.results.items:[data.location];
如果(位置.长度>0){
对于(i=0,len=locations.length;i
第二部分是添加click listener,它显示一个infobubble,并使用存储的placeId填充Place小部件:
resultSet.addListener("click" , function(evt) {
infoBubbles.openBubble("<div id='basicPlaceContainer'></div>",
evt.target.coordinate);
var basicPlace = new nokia.places.widgets.Place({
placeId: evt.target.placeId,
targetNode: "basicPlaceContainer",
template: "nokia.blue.bubble"
});
}, false);
resultSet.addListener(“单击”),函数(evt){
infoBubbles.openBubble(“,
目标坐标);
var basicPlace=new nokia.places.widgets.Place({
placeId:evt.target.placeId,
targetNode:“basicPlaceContainer”,
模板:“nokia.blue.bubble”
});
},假);
完整的工作示例如下所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9; IE=10" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Nokia Maps API for JavaScript Example: Search by category</title>
<meta name="description" content="Search by category"/>
<script type="text/javascript" charset="UTF-8" src="http://js.cit.api.here.com/se/2.5.3/jsl.js?with=all"></script>
</head>
<body>
<div id="mapContainer" style="width:540px; height:334px;"></div>
<script type="text/javascript" id="exampleJsSource">
/* Setup authentication app_id and app_code
*/
nokia.Settings.set("app_id", "YOUR APP ID");
nokia.Settings.set("app_code", "YOUR APP CODE");
// Use staging environment (remove the line for production environment)
nokia.Settings.set("serviceMode", "cit");
// Get the DOM node to which we will append the map
var mapContainer = document.getElementById("mapContainer");
// Create a map inside the map container DOM node
var map = new nokia.maps.map.Display(mapContainer, {
// Initial center and zoom level of the map
center: [52.51, 13.4],
zoomLevel: 10,
components: [
new nokia.maps.map.component.Behavior()
]
});
this.infoBubbles = new nokia.maps.map.component.InfoBubbles();
map.components.add(infoBubbles);
var searchCenter = new nokia.maps.geo.Coordinate(52.51, 13.4),
searchManager = nokia.places.search.manager,
resultSet;
// Function for receiving search results from places search and process them
var processResults = function (data, requestStatus, requestId) {
var i, len, locations, marker;
if (requestStatus == "OK") {
locations = data.results ? data.results.items : [data.location];
if (locations.length > 0) {
if (resultSet) map.objects.remove(resultSet);
resultSet = new nokia.maps.map.Container();
resultSet.addListener("click" , function(evt) {
infoBubbles.openBubble("<div id='basicPlaceContainer'></div>", evt.target.coordinate);
var basicPlace = new nokia.places.widgets.Place({
placeId: evt.target.placeId,
targetNode: "basicPlaceContainer",
template: "nokia.blue.bubble"
});
}, false);
for (i = 0, len = locations.length; i < len; i++) {
marker = new nokia.maps.map.StandardMarker(locations[i].position,
{ text: i+1 ,
placeId : locations[i].placeId});
resultSet.objects.add(marker);
}
map.objects.add(resultSet);
map.zoomTo(resultSet.getBoundingBox(), false);
} else {
alert("Your search produced no results!");
}
} else {
alert("The search request failed");
}
};
// Make a place search request
var category = "eat-drink";
map.addListener("displayready", function () {
searchManager.findPlacesByCategory({
category: category,
onComplete: processResults,
searchCenter: searchCenter
});
});
</script>
</body>
</html>
适用于JavaScript的诺基亚地图API示例:按类别搜索
/*设置身份验证应用程序id和应用程序代码
*/
nokia.Settings.set(“应用程序id”、“您的应用程序id”);
nokia.Settings.set(“应用程序代码”、“您的应用程序代码”);
//使用临时环境(删除生产环境的行)
诺基亚.Settings.set(“服务模式”、“cit”);
//获取要向其附加映射的DOM节点
var mapContainer=document.getElementById(“mapContainer”);
//在映射容器DOM节点内创建映射
var map=新的nokia.maps.map.Display(mapContainer{
//地图的初始中心和缩放级别
中间:[52.51,13.4],
zoomLevel:10,
组成部分:[
新的nokia.maps.map.component.Behavior()
]
});
this.infoBubbles=new nokia.maps.map.component.infoBubbles();
map.components.add(infoBubbles);
var searchCenter=new nokia.maps.geo.Coordinate(52.51,13.4),
searchManager=nokia.places.search.manager,
结果集;
//用于从地点搜索接收搜索结果并对其进行处理的功能
var processResults=函数(数据、请求状态、请求ID){
变量i、len、位置、标记;
如果(请求状态=“确定”){
位置=data.results?data.results.items:[data.location];
如果(位置.长度>0){
if(resultSet)map.objects.remove(resultSet);
resultSet=new nokia.maps.map.Container();
addListener(“单击”,函数(evt){
infoBubbles.openBubble(“,evt.target.coordinate”);
var basicPlace=new nokia.places.widgets.Place({
placeId:evt.target.placeId,
targetNode:“basicPlaceContainer”,
模板:“nokia.blue.bubble”
});
},假);
对于(i=0,len=locations.length;i
结果如下所示:
这帮助我理解了很多东西,谢谢。还有一个问题。如果我想显示地图上由php代码获得的坐标定义的一个地方的信息,我可以使用上面的示例吗?我的地图如果你试图访问服务器端的此处,那么你需要使用。我会请求一个使用
size=1
参数放置,如f