简体   繁体   中英

Add Severall Marker to Google Map

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

How about this link 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

Assuming you are using javascript api v3 you should check the documentation for adding markers.Hope this helps

simple paste this after code which creates your map (in variable named '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). Call them inside of "onModuleLoad" when you load the maps api. Also, you may want to make use of "MarkerOptions" for tooltips and icons. 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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