Does someone kn开发者_如何转开发ow how to add several marker on a single google map, I am googling this but getting in JavaScript, I am working with 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);
}
精彩评论