Created
March 17, 2011 17:38
-
-
Save jayzeng/874762 to your computer and use it in GitHub Desktop.
Displays a series pins with an index number and set a central point base upon all pins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<style type="text/css"> | |
.pushpin {position: absolute; text-align: center; width: 100%; font: normal normal bold 10pt/normal Arial, Helvetica, sans-serif; color: rgb(255, 255, 255); left: 0px; top: 5px;} | |
</style> | |
<script src="http://prototypejs.org/assets/2009/8/31/prototype.js"></script> | |
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1"></script> | |
<script> | |
var locations = [ | |
'1211 4th St #APT 3 Tacoma, WA 98403', | |
'341 Lake Forest Dr Allyn, WA 98524', | |
'3181 Old Belfair Hwy Belfair, WA 98528', | |
'3810 78th Avenue Ct W #APT G104 University Place, WA 98466', | |
'8325 29th West St University Place, WA 98466', | |
'2209 6th Pl Renton, WA 98056', | |
'8325 29th St W #APT A University Place, WA 98466', | |
'16 Polohina Ln Lahaina, HI 96761' | |
]; | |
var bingMapEnum = { | |
confidenceLevels : ["High", "Medium", "Low"], | |
precisionTypes : ["Interpolated", "Rooftop"], | |
}; | |
var bingMap = { | |
init: function(){ | |
count = 0; | |
allLat = []; | |
allLon = []; | |
map = new VEMap('myMap'); | |
map.LoadMap(); | |
map.SetZoomLevel(9); | |
this.geoCode(locations[0]); | |
}, | |
geoCode: function (address){ | |
if (address !== '') | |
{ | |
map.Find( | |
null, // what | |
address, // where | |
null, // VEFindType (always VEFindType.Businesses) | |
null, // VEShapeLayer (base by default) | |
0, // start index for results (0 by default) | |
1, // max number of results (default is 10) | |
null, // show results? (default is true) | |
null, // create pushpin for what results? (ignored since what is null) | |
null, // use default disambiguation? (default is true) | |
false, // set best map view? (default is true) | |
this.addPin // call back function | |
); | |
}; | |
var centralPoint = new VELatLong((this.getMinLat() + this.getMaxLat()) / 2, (this.getMinLon() + this.getMaxLon()) / 2); | |
map.SetCenter(centralPoint); | |
}, | |
addPin:function(layer, resultsArray, places, hasMore, errorMessage){ | |
if(places.length > 0) | |
{ | |
var shape = new VEShape( VEShapeType.Pushpin,places[0].LatLong); | |
var currentPlace = places[0]; | |
console.log(currentPlace); | |
bingMap.logInvalidAddress(currentPlace); | |
var location = currentPlace.LatLong; | |
allLat.push(currentPlace.LatLong.Latitude); | |
allLon.push(currentPlace.LatLong.Longitude); | |
var confidence = bingMapEnum.confidenceLevels[currentPlace.MatchConfidence]; | |
var precision = bingMapEnum.precisionTypes[currentPlace.Precision]; | |
shape.SetTitle(places[0].Name); | |
shape.SetCustomIcon("<img src='poi_precise_location.png'/><span class='pushpin'>" + | |
(count + 1) + | |
"</span>" | |
); | |
shape.SetDescription( | |
"Confidence LeveL: " + confidence + "<br>" + | |
"Precision: " + precision + "<br>" + | |
"Latitude: " + location.Latitude + "<br>" + | |
"Longitude" + location.Longitude + "<br>" | |
); | |
map.AddShape(shape); | |
} | |
count++; | |
if(count < locations.length){ | |
bingMap.geoCode(locations[count]); | |
} | |
}, | |
getSortedLat:function(){ | |
return allLat.sort(function(a,b){return a - b}); | |
}, | |
getSortedLon:function(){ | |
return allLon.sort(function(a,b){return a - b}); | |
}, | |
getMinLat:function(){ | |
this.getSortedLat(); | |
return allLat[0]; | |
}, | |
getMaxLat:function(){ | |
this.getSortedLat(); | |
return allLat[allLat.length - 1]; | |
}, | |
getMinLon:function(){ | |
this.getSortedLon(); | |
return allLon[0]; | |
}, | |
getMaxLon:function(){ | |
this.getSortedLon(); | |
return allLon[allLon.length - 1]; | |
}, | |
logInvalidAddress:function(address){ | |
if(address instanceof VEPlace){ | |
//Log down any address when its match confidence and match code are not good and high | |
if(address.MatchCode !== VEMatchCode.Good && address.MatchConfidence !== VEMatchConfidence.High){ | |
new Ajax.Request('invalidaddresslogger.php', | |
{ | |
method: 'post', | |
parameters: {timestamp: new Date().toString(), name: address.Name, matchcode: address.matchCode, precision: address.Precision, confidence: address.MatchConfidence, latitude: address.LatLong.Latitude, longitude: address.LatLong.Longitude}, | |
onSuccess: function(transport){ | |
var response = transport.responseText || "no response text"; | |
console.log("Success! \n\n" + response); | |
}, | |
onFailure: function(){ console.log('Something went wrong...')} | |
}); | |
} | |
} | |
} | |
} | |
document.observe("dom:loaded", function() { | |
// initialize map | |
bingMap.init(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id='myMap' style="position:relative; width:800px; height:600px;"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment