Read data from MySQL ?
-
Wednesday, March 14, 2007 2:35 PM
Hi
Is it possible to read map pins [ lat & lng ] from a MySQL database ?
So that I can run tho the database pulling all the PIN's and plot them on my map?
Tried several things, but keep getting errors, if someone has an example of code I could look at, this would be great.
Many thanks.
My Code so far is this...
[code]
<?php
// get some initial data from databse
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.titleStyle
{
font-family:Verdana;
font-size:12pt;
font-weight:bold;
}
.iconStyle
{
position:relative;
top:-15px;
}
.detailsStyle
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
text-align:left;
}
</style><script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
var ffv = 0;
var ffn = "Firefox/";
var ffp = navigator.userAgent.indexOf(ffn);
if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
// If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
if (ffv >= 1.5) {
Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
}
</script>
<script>
var map = null;
var pinID = 1;function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.SetCenterAndZoom(new VELatLong(<?=$getlat?>, <?=$getlon?>), 5);}
function AddPin(lat1,lon1)
{
var pin = new VEPushpin(
pinID,
new VELatLong(lat1, lon1),
'/images/msn/car_icon.gif',
'Kathmandu',
'<img src="./img/Pict92.jpg"><br>'+
'One of the many rainy days we had in Kathmandu. '+
'I guess that\'s what you get for traveling during monsoon season.',
'iconStyle',
'titleSytle',
'detailsStyle'
);
map.AddPushpin(pin);
pinID++;
}
<?php// loop thro the query and pass lat & lng to Add Pin() function
while($row = mysql_fetch_array($result))
{$lat1 = $row['L_lat'];
$lon1 = $row['L_lon'];
?>AddPin(<?php echo $lat1; ?>,<?php echo $lon1; ?>);
<?php
}?>
</script>
</head>
<body onload="GetMap();"><div id='myMap' style="position:relative; width:100%; height:75%;"></div>
</body>
</html>[/code]
It displays the map, but reports this error....
document.body has no properties
All Replies
-
Wednesday, March 14, 2007 9:59 PMModerator
Not a PHPer but if you where tring to insert the AddPins calls should they not be part of the GetMap function that is called when the document body is loaded?
I think you did a page view source the html generated would show the javascript is in the wrong place.
You want some thing like this output yeah?
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.SetCenterAndZoom(new VELatLong(50, 60), 5);Addpin(20,30);
AddPin(30,40);
AddPin(50,60);
}
function AddPin(lat1,lon1)
{
var pin = new VEPushpin(
pinID,
new VELatLong(lat1, lon1),
'/images/msn/car_icon.gif',
'Kathmandu',
'<img src="./img/Pict92.jpg"><br>'+
'One of the many rainy days we had in Kathmandu. '+
'I guess that\'s what you get for traveling during monsoon season.',
'iconStyle',
'titleSytle',
'detailsStyle'
);
map.AddPushpin(pin);
pinID++;
}John.
- Marked As Answer by Richard_BrundrittMicrosoft Employee, Moderator Saturday, November 28, 2009 12:27 PM
-
Tuesday, April 10, 2007 7:30 PM
Hi,
I was trying with Postgre and write this function to convert Postgres-MySQL Polygon to Array poligon for VE, this is the code:
function convertoVE(punts){
var i=0;
var a2=0;
var array = new Array();
var caracter = "";
var lat;
var lon;
var apuntador=1;
for(i;i<=punts.length;i++){
if((punts.charAt(i)!=")")&&(punts.charAt(i) != ",")){
if(punts.charAt(i) == "("){
i=i+1;
if(punts.charAt(i) == "("){
i=i+1;
}
for(i;punts.charAt(i) != ",";i++){
caracter = caracter+punts.charAt(i);
}
lat = caracter;
//alert("lat"+lat);
caracter = "";
i++;
for(i;punts.charAt(i) != ")";i++){
caracter = caracter+punts.charAt(i);
}
lon = caracter;
//alert("lon"+lon);
caracter = "";
array[a2] = new VELatLong(lat, lon);
//alert(array[a2]);
a2++;
}
}
}
return(array);
}if you need only change a point delete line an change:
from:
var array = new Array();
to:var punto;
from:
array[a2] = new VELatLong(lat, lon);
a2++;
to:
punto = new VELatLong(lat, lon);
from:
return(array);
to:
return(punto);
I used and looks good.

