Hello, i'm a student and i'm currently developing a Flex Mobile app
for a final project using GoogleMaps. After some research in your
tutorials i managed to make a small app that shows the map and some
random markers.
Then i tried to load some markers using a PHP file to create the XML
file i need to send my app the markers,
The error i get is this:
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at views::Mapa/createMarker()[C:\Users\Zebrah\Adobe Flash Builder
4.5\Tutorial Flex Mobile\GoogleMaps Test\src\views\Mapa.mxml:101]
at views::Mapa/readXml()[C:\Users\Zebrah\Adobe Flash Builder
4.5\Tutorial Flex Mobile\GoogleMaps Test\src\views\Mapa.mxml:96]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
The code for the Flex Mobile app is:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects)
here
-->
</fx:Declarations>
<s:Panel title="Xml Parsing with Google Maps Demo" width="100%"
height="100%">
<mx:UIComponent id="mapHolder"
initialize="onHolderCreated(event);"
resize="onHolderResized(event)"
width="100%" height="100%"/>
</s:Panel>
<fx:Script>
<![CDATA[
import com.google.maps.InfoWindowOptions;
import com.google.maps.LatLng;
import com.google.maps.LatLngBounds;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapMouseEvent;
import com.google.maps.MapOptions;
import com.google.maps.MapType;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.overlays.GroundOverlay;
import com.google.maps.overlays.GroundOverlayOptions;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Polyline;
private var map:Map;
private var blueIcon:Class;
private var greenIcon:Class;
private var customIcons:Object =
{ "restaurant": blueIcon,
"bar": greenIcon
};
public function onHolderCreated(event:Event):void {
map = new Map();
map.key = "ABQIAAAA9iNYq39n_ERvjVXy2sp8hxTWoPrV-
LkcatU6FDhi4genfkaxbhRDJBAxj7heO6UlDNKId6WnDajf0w";
map.addEventListener(MapEvent.MAP_READY,
onMapReady);
mapHolder.addChild(map);
map.url="http://127.0.0.1:8888";
map.sensor="true";
}
public function onHolderResized(event:Event):void {
map.setSize(new Point(mapHolder.width,
mapHolder.height));
}
private function onMapReady(event:Event):void {
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.addControl(new ZoomControl());
map.setCenter(new LatLng(47.608940,
-122.340141), 13,
MapType.NORMAL_MAP_TYPE);
getXml();
}
public function getXml():void {
var xmlString:URLRequest = new
URLRequest("http://127.0.0.1:8888/
php_crearXML.php");
var xmlLoader:URLLoader = new
URLLoader(xmlString);
xmlLoader.addEventListener("complete", readXml);
}
public function readXml(event:Event):void {
var markersXML:XML = new XML(event.target.data);
var markers:XMLList = markersXML..marker;
for (var i:Number = 0; i < markers.length();
i++) {
var marker:XML = markers[i];
var name:String = marker.@nombre;
var address:String = marker.@direccion;
var type:String = marker.@tipo;
var latlng:LatLng = new
LatLng(marker.@lat, marker.@lng);
var marker2:Marker =
createMarker(latlng, name, address, type);
map.addOverlay(marker2);
}
}
public function createMarker(latlng:LatLng, name:String,
address:String, type:String): Marker {
var marker:Marker = new Marker(latlng, new
MarkerOptions({icon:
new customIcons[type], iconOffset: new Point(-16, -32)}));
var html:String = "<b>" + name + "</b> <br/>" +
address;
marker.addEventListener(MapMouseEvent.CLICK,
function(e:MapMouseEvent):void {
marker.openInfoWindow(new
InfoWindowOptions({contentHTML:html}));
});
return marker;
}
]]>
</fx:Script>
</s:View>
The PHP code i'm using for the XML parsing is:
<?php
require("php_rotrDB_info.php"); //I store here the info for
username / password / database name
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ('127.0.0.1',$username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM marcadores WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
//header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("nombre",$row['nombre']);
$newnode->setAttribute("direccion", $row['direccion']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("tipo", $row['tipo']);
}
echo $dom->saveXML();
?>
And here its the XML for the table on MySQL database:
<database name="rotr">
<!-- Tabla marcadores -->
<table name="marcadores">
<column name="ID">1</column>
<column name="nombre">Pan Africa Market</column>
<column name="direccion">1521 1st Ave, Seattle, WA</
column>
<column name="lat">47.608940</column>
<column name="lng">-122.340141</column>
<column name="tipo">restaurant</column>
</table>
<table name="marcadores">
<column name="ID">2</column>
<column name="nombre">Buddha Thai & Bar</column>
<column name="direccion">2222 2nd Ave, Seattle, WA</
column>
<column name="lat">47.613590</column>
<column name="lng">-122.344391</column>
<column name="tipo">bar</column>
</table>
<table name="marcadores">
<column name="ID">3</column>
<column name="nombre">The Melting Pot</column>
<column name="direccion">14 Mercer St, Seattle, WA</
column>
<column name="lat">47.624561</column>
<column name="lng">-122.356445</column>
<column name="tipo">restaurant</column>
</table>
<table name="marcadores">
<column name="ID">4</column>
<column name="nombre">Ipanema Grill</column>
<column name="direccion">1225 1st Ave, Seattle, WA</
column>
<column name="lat">47.606365</column>
<column name="lng">-122.337654</column>
<column name="tipo">restaurant</column>
</table>
<table name="marcadores">
<column name="ID">5</column>
<column name="nombre">Sake House</column>
<column name="direccion">2230 1st Ave, Seattle, WA</
column>
<column name="lat">47.612823</column>
<column name="lng">-122.345673</column>
<column name="tipo">bar</column>
</table>
<table name="marcadores">
<column name="ID">6</column>
<column name="nombre">Crab Pot</column>
<column name="direccion">1301 Alaskan Way, Seattle, WA</
column>
<column name="lat">47.605961</column>
<column name="lng">-122.340363</column>
<column name="tipo">restaurant</column>
</table>
<table name="marcadores">
<column name="ID">7</column>
<column name="nombre">Mama's Mexican Kitchen</column>
<column name="direccion">2234 2nd Ave, Seattle, WA</
column>
<column name="lat">47.613976</column>
<column name="lng">-122.345467</column>
<column name="tipo">bar</column>
</table>
<table name="marcadores">
<column name="ID">8</column>
<column name="nombre">Wingdome</column>
<column name="direccion">1416 E Olive Way, Seattle, WA</
column>
<column name="lat">47.617214</column>
<column name="lng">-122.326584</column>
<column name="tipo">bar</column>
</table>
<table name="marcadores">
<column name="ID">9</column>
<column name="nombre">Piroshky Piroshky</column>
<column name="direccion">1908 Pike pl, Seattle, WA</
column>
<column name="lat">47.610126</column>
<column name="lng">-122.342834</column>
<column name="tipo">restaurant</column>
</table>
</database>
I'll apreciate any suggestions on this. Going to keep searching what
is wrong with this, thanks in advance :D
--
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en.