You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
simple-yewu/frontend/web/js/artDialog/_doc/ajaxContent/googleMaps.html

96 lines
3.0 KiB

<div id="map" style="width:558px">
<div>地址: <input id="map_address" value="" style="width:200px; padding:4px;" /> <button id="map-search-sumbit">搜 索</button></div>
<div id="map_canvas" style="width:558px; height:360px;"></div>
</div>
<script type="text/dialog">
var dialog = this;
var getScript = function(src, fn, doc) {
doc = doc || document;
var script = doc.createElement('script');
script.language = "javascript";
script.charset = $.charset;
script.type = 'text/javascript';
script.onload = script.onreadystatechange = function() {
if (!script.readyState || 'loaded' === script.readyState ||'complete' === script.readyState) {
fn && fn();
script.onload = script.onreadystatechange = null;
script.parentNode.removeChild(script);
};
};
script.src = src;
doc.body.appendChild(script);
};
getScript("http://maps.googleapis.com/maps/api/js?sensor=false&language=zh_CN", function () {
var map, geocoder;
function initialize() {
var latlng = new google.maps.LatLng(39.904214, 116.407413);//39.904214,116.407413
var options = {
zoom: 11,
center: latlng,
disableDefaultUI: true,
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: false,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
geocoder = new google.maps.Geocoder();
geocoder.geocode({latLng: latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[3]) {
document.getElementById("map_address").value = results[3].formatted_address;
}
}
});
dialog.title('google mpas')
.button({name: '截图', callback: function () {
var center = map.getCenter().lat() + ',' + map.getCenter().lng(),
zoom = map.getZoom(),
maptype = map.getMapTypeId(),
url = 'http://maps.googleapis.com/maps/api/staticmap';
url += '?center=' + encodeURIComponent(center);
url += '&zoom=' + encodeURIComponent(zoom);
url += '&size=558x360';
url += '&maptype=' + encodeURIComponent(maptype);
url += '&markers=' + encodeURIComponent(center);
url += '&language=zh_CN';
url += '&sensor=false';
art.dialog.through({title: false, content: '<img src="' + url + '" />', padding: 0, width: 558, height: 360, lock: true});
return false;
}, focus: true})
.position('50%', 'goldenRatio');
document.getElementById("map-search-sumbit").onclick = function () {
var input = document.getElementById('map_address');
search(input.value);
};
}
function search(address) {
if (!map) return;
geocoder.geocode({address : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setZoom(11);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Invalid address: " + address);
}
});
}
});
</script>