Computer Hardware Forum - TweakPC

Computer Hardware Forum - TweakPC (https://www.tweakpc.de/forum/)
-   Programmiersprachen (https://www.tweakpc.de/forum/programmiersprachen/)
-   -   Proplem mit Javascript (map24 API) (https://www.tweakpc.de/forum/programmiersprachen/44072-proplem-mit-javascript-map24-api.html)

LeoHart 30.12.2006 23:52

Proplem mit Javascript (map24 API)
 
Hallo,
hab ein "kleines" Problem mit der Einbindung von map24 auf meiner HP. Zwar gibt es auf der map24 HP eine sehr gute [URL="http://devnet.map24.com/manuals/doku.php?id=ajax:1.0:introduction:introduction"]Tutorial Seite[/URL] aber die hilft mir hier nicht weiter. Wollte folgende Funtkionen einbinden einmal das man zwischen statisch und interaktiver Karte wählen kann, was auch immer funktioniert :) , dann soll die Route berechnet werden [Routing] und ein beliebiger Standort [Geocoding Basics]

Hab das Problem das sich die Funktion Routing und Geocoding Basics irgendwie stören. Bei diesem Code unten funktioniert Geocoding Basics aber bei der Funktion Routing wird keine Route berechnet sondern nur der Startort. Sehe aber nicht wo da der Fehler sein soll.

[code]<html>

<head>
<script language="javascript" type="text/javascript" src="http://api.map24.com/ajax/1.2/?init=default"></script>
<script language="javascript" type="text/javascript" >
var map = null;

function goMap24() {

map = Map24.Webservices.getMap24Application({
AppKey:"00000000000000000000000000000000",
MapArea:document.getElementById("maparea"),
Maptype: "JAVA",
MapWidth: 550,
MapHeight: 550
});
}

function setMGI(){
map.setMaptype( "MGI" );
}

function setJava(){
map.setMaptype( "JAVA" );
}

function calculateRouteAddr( start, destination ){
if( Map24.isNull( start ) ) return;
if( Map24.isNull( destination ) ) return;

geocodeStartAndDestination( start, destination );
return;
}

function geocodeStartAndDestination( start, destination ){
//1. Geocode the start address
geocode( start, onGeocodeStart )

//2. When start address has been geocoded, then geocode destination address
function onGeocodeStart( geoRes ){
startGeocoded = geoRes.firstResult;
geocode( destination, onGeocodeDest )
}
//3. When both start and dest address have been geocoded, then start route calculation
function onGeocodeDest( geoRes ){
destinationGeocoded = geoRes.firstResult;
calculateRouteCoord( startGeocoded, destinationGeocoded );
}
}

//Calculate a route between two addresses
function calculateRouteCoord( startGeocoded, destinationGeocoded ){
if( Map24.isNull( startGeocoded ) ) return;
if( Map24.isNull( destinationGeocoded ) ) return;

var routeRequest = new Map24.Webservices.Request.CalculateRoute( map );
routeRequest.Start = new Map24.Webservices.Request.CalculateRoute.CoordinateAndAddress();
routeRequest.Start.Coordinate = new Map24.Coordinate( startGeocoded.Coordinate.Longitude,
startGeocoded.Coordinate.Latitude );
routeRequest.Destination = new Map24.Webservices.Request.CalculateRoute.CoordinateAndAddress();
routeRequest.Destination.Coordinate = new Map24.Coordinate( destinationGeocoded.Coordinate.Longitude,
destinationGeocoded.Coordinate.Latitude );
map.Webservices.sendRequest( routeRequest );

//This listener is called when the route calculation has finished
map.onCalculateRoute = function( event ){
var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
mrcContainer.push(
new Map24.Webservices.MRC.DeclareMap24RouteObject({
MapObjectID: "actualRoute",
Map24RouteID: event.Info.RouteID,
Color: new Map24.Color( 255, 0, 0, 180 )
})
);
//Center the map view on the route visualization
mrcContainer.push( genSetMapView( 0, 70, null, null, "actualRoute" ) );

//Enable the visibility of the route
mrcContainer.push( genControlMapObject( "ENABLE", "actualRoute" ) );

map.Webservices.sendRequest( mrcContainer );
}
}

//Geocoding
function geocode( address, onGeoFunc ){
map.Webservices.sendRequest(
new Map24.Webservices.Request.MapSearchFree(map, {
SearchText: address,
MaxNoOfAlternatives: 50
})
);

map.onMapSearchFree = function( event ){
var geoRes = new Object();
geoRes.Alternatives = event.Alternatives;
geoRes.firstResult = geoRes.Alternatives[0];

onGeoFunc( geoRes );
}
}

//Factory functions
function genSetMapView( ClippingWidth, ClippingPercent, lon, lat, objID ){
//Hashtable Clip { MinimumWidth: ClippingWidth, ViewPercentage: ClippingPercent } is created
var Clip = new Array();
if( !Map24.isNull( ClippingWidth ) )
Clip['MinimumWidth'] = ClippingWidth;
if( !Map24.isNull( ClippingPercent ) )
Clip['ViewPercentage'] = ClippingPercent;

if( !Map24.isNull( lon ) && !Map24.isNull( lat ) )
{
var SetMapView = new Map24.Webservices.MRC.SetMapView({
ClippingWidth: new Map24.Webservices.ClippingWidth( Clip ),
Coordinates: new Map24.Coordinate( lon, lat )
});
}
else if( !Map24.isNull( objID ) )
{
var SetMapView = new Map24.Webservices.MRC.SetMapView({
ClippingWidth: new Map24.Webservices.ClippingWidth( Clip ),
MapObjectIDs: objID
});
}
return SetMapView;
}

function genControlMapObject( Control, objID ){
var ControlObject = new Map24.Webservices.MRC.ControlMapObject({
Control: Control,
MapObjectIDs: objID
});
return ControlObject;
}

function geocode( addressString ){
map.Webservices.sendRequest(
new Map24.Webservices.Request.MapSearchFree(map, {
SearchText: addressString,
MaxNoOfAlternatives: 50
})
);

map.onMapSearchFree = function( event ){
var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl( map );
var firstResult = event.Alternatives[0];
var lon = firstResult.Coordinate.Longitude;
var lat = firstResult.Coordinate.Latitude;

mrcContainer.push(
new Map24.Webservices.MRC.SetMapView({
Coordinates: new Map24.Coordinate( lon, lat ),
ClippingWidth: new Map24.Webservices.ClippingWidth(
{ MinimumWidth: 5000 }
)
})
);
map.Webservices.sendRequest( mrcContainer );
}
}
</script>

</head>
[/code]

[html]
<b>Ort</b>
<input id="req" type="text" style="margin-top:8px" size=20 maxlength=50 value='000 Ort'>

<input type="image" src='http://img.map24.com/map24/portal/fr-fr/dyna/btn_next0.png' style="margin-top:5px"
onclick="return geocode(document.getElementById('req').value)">


<b>Route</b>
Start:
<input type='text' name='start_address' id='start_address' size='20' value=''>
Ziel:
<input type='text' name='dest_address' id='dest_address' size='20' value='000 Ort'>
<a href='javascript:calculateRouteAddr(document.getElementById("start_address").value,
document.getElementById("dest_address").value);'>
<img src='http://img.map24.com/map24/portal/fr-fr/dyna/btn_next0.png' border=0>
[/html]
Dachte auch schon daran das vieleicht etwas mit den Variabeln im html-Teil nicht stimmt aber sehe hier auch nichts.

Sollte noch anmerken das ich mich mit Javascript nicht auskenne, habe lediglich die Funktionen einander gesetzt und versucht darauf zu achten das die geschweiften Klammen stimmen.

Hoffe ihr kennt euch mit map24 etwas aus ^^

:Edit:
was ich noch vergessen zu erwähnen habe ist das, dass Applet nur unter FiferFox funktioniert, der IE zeigt gar nichts an außer einen Platzhalter mit der größe des Applets.


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:55 Uhr.

Powered by vBulletin® Version 3.8.10 (Deutsch)
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.5.2 ©2010, Crawlability, Inc.