/** * Convert string to JS date type * @param {string} str format 2008-08-01 12:12:12 * @return Date/function getDate (str) {var STRs
= Str.split ("");
var strymd = Strs[0].split ("-");
var strhm = Strs[1].split (":");
return new Date (Strymd[0], parseint (strymd[1]-1), strymd[2], strhm[0], strhm[1]); /** * Create map default IP location to get current city initialization map * @param {Number} longitude longitude * @param {number} latitude Latitude * @param {number} level
Zoom level * @return Bmap/function Createbmap (longitude,latitude,level) {var map = new Bmap.map ("container"); if (IsBlank (longitude) | | | IsBlank (latitude)) {//default to get the current city initialization map function myfun (result) {var cityname = ResU in IP location
Lt.name;
Map.setcenter (CityName);
var mycity = new Bmap.localcity ();
Mycity.get (Myfun);
} map.centerandzoom (New Bmap.point (longitude, latitude), level);
Map.addcontrol (New Bmap.maptypecontrol ({Maptypes:[bmap_normal_map,bmap_satellite_map,bmap_hybrid_map]})); Map.setmaptype (New Maptype ().
BMAP_SATELLITE_MAP); Map.enableScrollwheelzoom (); Enable wheel zoom out, default disable Map.enablecontinuouszoom (); Enable map inertia drag-and-drop, default disable Map.addcontrol (new Bmap.navigationcontrol ()); Add default zoom translation control//Map.addcontrol (new Bmap.navigationcontrol {anchor:bmap_anchor_top_right, Type:bmap_navigation_ Control_small})); The upper-right corner contains only the pan and Zoom button Map.addcontrol (new Bmap.navigationcontrol {anchor:bmap_anchor_bottom_left, Type:bmap_navigation_ Control_pan})); The lower left corner contains only the translation button Map.addcontrol ({anchor:bmap_anchor_bottom_right, type:bmap_navigation_ Control_zoom})); The lower-right corner contains only the zoom button Map.addcontrol (new Bmap.scalecontrol ()); Add the default scale control Map.addcontrol (new Bmap.scalecontrol ({anchor:bmap_anchor_top_left})); Left Top//Map.addcontrol (new Bmap.scalecontrol ({anchor:bmap_anchor_top_right})); Upper right Map.addcontrol (new Bmap.scalecontrol ({anchor:bmap_anchor_bottom_left})); Lower left Map.addcontrol (new Bmap.scalecontrol ({anchor:bmap_anchor_bottom_right}));
lower right return map; /** * Create a single callout * @param {Object} map Bmap * @param {number} lonGitude Longitude * @param {number} latitude Latitude * @param {String} msg callout Information title/function Createmarker (map, longitude, latitude, MSG, icon) {if (Isnotblank (longitude) && Isnotblank (latitude)) {var thepoint = new Bmap.point (longitude, Lati
Tude); var marker1 = new Bmap.marker (thepoint);
Create a callout if (Isnotblank (icon)) {Marker1.seticon (icon);
var name = Msg.split ("Mobile Number:") [0];
Marker1.settitle (name); Map.addoverlay (Marker1); Add annotations to map//Info window set var opts = {//width:250,//Info window width//height:100,//Info window height title: Isnotblank (msg)?
msg: '//Info window Title} var gc = new Bmap.geocoder ();
Gc.getlocation (Thepoint, function (RS) {//rs.address;//address var addcomp = rs.addresscomponents; var province = Isnotblank (addcomp.province)?
Addcomp.province: ""; var city = Isnotblank (addcomp.city)?
Addcomp.city: "";; var provincecity = province==city?
city:province+city; var Theadr = provincecity + "" + (ISNOTBLank (addcomp.district)? Addcomp.district + "": "") + (Isnotblank (addcomp.street)? Addcomp.street + "": "") + (Isnotblank (addcomp.streetnumber)?
Addcomp.streetnumber: "");
var ADR = "At present:" + (Isnotblank (THEADR)? theadr+ "near": "Unknown"); var infoWindow1 = new Bmap.infowindow (adr,opts);
Create Information window Marker1.addeventlistener ("Click", Function () {This.openinfowindow (INFOWINDOW1);});
});
return marker1; /** * Creates a callout point and draws the line * @param map * @param arr * @returns/function Createmarkerspolyline (map, arr) {if IsBlank (a RR) | |
Arr.length < 1) {return null;
var now = new Date ();
var points = new Array ();
for (Var i=0;i<arr.length;i++) {if (IsBlank (arr[i))) {continue;
var pl = Arr[i];
var thepoint = new Bmap.point (Pl.longitudebaidu, Pl.latitudebaidu);
Points.push (Thepoint); var marker = new Bmap.marker (thepoint); Create callout var icon = i = = 0?
Endiconbaidu: (i = = arr.length-1? starticonbaidu:null); if (IsBlank (icon)) {var dn= parseint ((now-getdate (Arr[i].keeptime))/1000/60);
Converts the difference in milliseconds to minutes if (dn>10 && dn<=30) {icon = Dull_redbaidu; else if (DN >) {icon = Greyiconbaidu;//Identity is gray}} if (Isnotblank (ICO
N)) {Marker.seticon (icon);
} marker.settitle (Pl.realname);
var title = Pl.realname + "mobile number:" + Pl.phone + "time:" + pl.keeptime;
var address = "is currently in:" + (Isnotblank (pl.addressbaidu)? Pl.addressbaidu: ' Unknown ');
Fun_infowin (marker, title, address); Map.addoverlay (marker);
Add annotations to the map DrawPolyline (map, points); /** * Draw Line * @param bmap * @param points/function DrawPolyline (BMAP, points) {if (Points==null | | points.length&
Lt;=1) {return; } bmap.addoverlay (New Bmap.polyline (points, {strokecolor: "Blue", Strokeweight:3, strokeopacity:0.5})); Draw line}/** * Set pop-up form information * * @param marker * @param thepoint * @param msg/function fun_infowin2 (marker, tHepoint, title) {//Info window set var opts = {//width:250,//Info window width//height:100,//Info window height Title:is Notblank (title)?
Title: '//Info window Title} var gc = new Bmap.geocoder ();
The Address resolution gc.getlocation (Thepoint, function (RS) {var Addcomp = rs.addresscomponents is obtained according to the geographical coordinates. var province = Isnotblank (addcomp.province)?
Addcomp.province: ""; var city = Isnotblank (addcomp.city)?
Addcomp.city: "";; var provincecity = province==city?
city:province+city; var Theadr = provincecity + "" + (Isnotblank (addcomp.district)? Addcomp.district + "": "") + (Isnotblank (addcomp.street)? Addcomp.street + "": "") + (Isnotblank (addcomp.streetnumber)?
Addcomp.streetnumber: "");
var ADR = "At present:" + (Isnotblank (THEADR)? theadr+ "near": "Unknown"); var infoWindow1 = new Bmap.infowindow (adr,opts);
Create Information window Marker.addeventlistener ("Click", Function () {This.openinfowindow (INFOWINDOW1);});
}); function Fun_infowin (marker, title, content) {//Info window set var opts = {TitlE:isnotblank (title)? Title: '//Info window title} marker.addeventlistener (' Click ', Function () {This.openinfowindow (new Bmap.infowindow) (Content, O
pts)); /** * Create multiple callouts * @param {Object} map Bmap * @param {array} arr array */function Createmarkerslbl (map, arr) {if (Isblan K (arr) | |
Arr.length < 1) {return null;
} map.clearoverlays ();
var points = new Array ();
for (Var i=0;i<arr.length;i++) {if (IsBlank (arr[i))) {continue;
var pl = Arr[i];
var thepoint = new Bmap.point (Pl.longitudebaidu, Pl.latitudebaidu);
Points.push (Thepoint); var marker = new Bmap.marker (thepoint);
Create callout Marker.settitle (pl.realname);
var title = Pl.realname + "mobile number:" + Pl.phone + "time:" + pl.keeptime;
var address = "is currently in:" + (Isnotblank (pl.addressbaidu)? Pl.addressbaidu: ' Unknown ');
Fun_infowin (marker, title, address); Map.addoverlay (marker); Add annotations to the map marker.setanimation (bmap_animation_bounce); Beat animation//Create text callout object above icon Callout Point var opts = {position: Thepoint,//Specify the geographical location of the text callout offset:new bmap.size (-20,-58)//Set the text offset (above the callout point)} var label = new Bmap.lab
El (Name, opts); Label.setstyle ({"padding": "2px", "Border": "1px solid #CCCCCC", "Display": "Block", "Filter": "ALP
Ha (opacity=62) ","-moz-opacity ":" 0.62 "," opacity ":" 0.62 "," FontSize ":" 13px ",});
Map.addoverlay (label);
} map.setviewport (points);
/** * Set immediate positioning left online personnel refresh time, unit (seconds)/var onlineinterval = 60*3;
/** * Set the waiting time for the Instant Location query, unit (seconds)/var positiontimeout = 30;
/** * Set the step size of the Instant Locator query (seconds)/var positioninterval = 3; /** * start tag picture */var Starticonbaidu = new Bmap.icon (".
/images/icons/marker_start.png ", New Bmap.size (40,40)); /** * end tag picture */var Endiconbaidu = new Bmap.icon (".
/images/icons/marker_end.png ", New Bmap.size (40,40)); /** * Gray Mark picture/var Greyiconbaidu = new Bmap.icon (".
/images/icons/marker_grey.png ", New Bmap.size (20,30)); /** * Dark red mark picture/var Dull_redbaidu = new Bmap.icon (". /images/icons/marker_dull_red.png ", New Bmap.size (20,30));
Map.clearoverlays (); Clearly marked
Refer to JS 1.4 without a key
<script src= "http://api.map.baidu.com/api?v=1.4" type= "Text/javascript" ></script>