简体   繁体   English

将Somelmarker标记添加到Google Map

[英]Add Severall Marker to Google Map

有人知道如何在单个Google地图上添加多个标记吗,我正在使用Google搜索,但是正在使用JavaScript,正在使用GWT

How about this link http://code.google.com/p/gwt-google-apis/wiki/MapsGettingStarted 该链接如何http://code.google.com/p/gwt-google-apis/wiki/MapsGettingStarted

In the middle of the page there is an example: 在页面中间有一个示例:

// Add a marker
map.addOverlay(new Marker(cawkerCity));

Edit:Sorry just saw the javascript part.Please post some code and what api you are using so we can examine this question more clearly 编辑:很抱歉,刚刚看到了javascript部分。请发布一些代码以及您使用的是什么api,以便我们可以更清楚地检查此问题

Assuming you are using javascript api v3 you should check the documentation for adding markers.Hope this helps 假设您使用的是javascript API v3,则应查看文档以添加标记。希望这会有所帮助

simple paste this after code which creates your map (in variable named 'map'): 简单地将其粘贴在创建地图的代码之后(在名为“ map”的变量中):

var myLatlng = new google.maps.LatLng(-15.363882,121.044922);
var marker = new google.maps.Marker({
  position: myLatlng, 
  map: map, 
  title: "Marker text"
}); 

Here's two functions that do exactly what you need (addMarker, loadTestData). 这有两个功能完全可以满足您的需求(addMarker,loadTestData)。 Call them inside of "onModuleLoad" when you load the maps api. 加载地图api时,在“ onModuleLoad”内部调用它们。 Also, you may want to make use of "MarkerOptions" for tooltips and icons. 另外,您可能要使用“ MarkerOptions”作为工具提示和图标。 The code below does, but you don't have to. 下面的代码可以,但是您不必这样做。

final MapWidget map = new MapWidget();

public void onModuleLoad(){
    Maps.loadMapsApi("put your key here", "2", false, new Runnable() {
        public void run() {
           loadTestData();
           final DockLayoutPanel dock = new DockLayoutPanel(Unit.PX);
           dock.addNorth(map, 500);

           // Add the map to the HTML host page
           RootLayoutPanel.get().add(dock);
        }
    });
}

private void addMarker(String name, double lat, double lon){
   LatLng latlong = LatLng.newInstance(lat, lon);
   MarkerOptions markerOptions = MarkerOptions.newInstance();
   markerOptions.setIcon(Icon.newInstance("/img/ship.png"));
   markerOptions.setTitle(name);  
   Marker marker = new Marker(latlong, markerOptions);
   map.addOverlay(marker);
}

private void loadTestData() {
   addMarker("SHIP1", 20.303417, -108.632812);
   addMarker("SHIP2", 24.527134, -116.191406);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM