Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Last active November 20, 2015 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgenvn/ce9c5fc997165d16a3d2 to your computer and use it in GitHub Desktop.
Save xgenvn/ce9c5fc997165d16a3d2 to your computer and use it in GitHub Desktop.
amap with english and chinese
<div style="display:none" id="amap-container">
<h3 class="box-header">Map</h3>
<div style="height: 400px; margin-top: 10px;" id="myMap">
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=KEY"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
var s1 = "LONG";
var s2 = "LAT";
var mapContainer = document.getElementById("myMap");
if ((s1 == " " && s2 == " ") || (s1 == '' || s2 == '')) {
document.getElementById("amap-container").style.display = "none";
} else {
document.getElementById("amap-container").style.display = "block";
var markerTitle = "TITLE";
var contentString = "CONTENT";
var venueMapObj = new AMap.Map(mapContainer, {
lang: "zh_en",
resizeEnable: true,
dragEnable: true,
zoomEnable: true,
zooms: [3, 18], //地图显示的缩放级别范围,在PC上,默认为[3,18],取值范围[3-18];在移动设备上,默认为[3-19],取值范围[3-19]
view: new AMap.View2D({
center: new AMap.LngLat(s1, s2),
zoom: 15
})
});
venueMapObj.plugin(["AMap.ToolBar"], function () {
var toolBar = new AMap.ToolBar();
toolBar.hideDirection();
toolBar.hideLocation();
venueMapObj.addControl(toolBar);
});
var venueMarker = new AMap.Marker({
map: venueMapObj,
draggable: false,
icon: "http://www.timeoutshanghai.com/images/pinForMap.png",
offset: new AMap.Pixel(0, 0),
animation: "AMAP_ANIMATION_DROP",
title: markerTitle,
clickable: true
});
var venueInfoWindow = new AMap.InfoWindow({
isCustom: false,
content: contentString,
offset: new AMap.Pixel(0, 0),
autoMove: true,
showShadow: true
});
var onClickInfoWindow = function () {
venueInfoWindow.open(venueMapObj, venueMarker.getPosition());
};
AMap.event.addListener(venueMarker, 'click', onClickInfoWindow);
onClickInfoWindow();
}
});
</script>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment