I am trying to make waze react and send me back lat,lon coordinates upon click. I managed to do this with OpenLayers, but waze doesn't respond. I don't know if the event has been registered or not even, and if it did, maybe the mouse don't fire the event... How can I find out ?
Here's the code snippet:
function onInit(){
var map = g_waze_map.map;
// MY STUFF
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
drag: new OpenLayers.Control.DragFeature(vectors)
};
for(var key in controls) {
map.addControl(controls[key]);
}
size = new OpenLayers.Size(21,25);
offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);
markers = new OpenLayers.Layer.Markers(开发者_开发问答 "Markers" );
map.addLayer(markers);
map.events.register("click", map, function(e) {
var position = map.getLonLatFromPixel(e.xy);
// alert(position.lon.toFixed(3) + ', ' + position.lat.toFixed(3));
alert("Mouse click");
});
}
Thanks !
I don't know what the Waze API does but you can achieve the same thing using the MousePosition control. Just add it an instance of it to the map and it shows the current lonlat on top of the map.
EDIT: It looks your onInit
function which registers the click callback never gets called. Your script has two g_waze_config
variables, the one which contains a reference to the onInit
function is declared only after the Waze script is included, causing it not to get called.
精彩评论