Geolocation 将标记从SQL数据库添加到OSM

Geolocation 将标记从SQL数据库添加到OSM,geolocation,openstreetmap,Geolocation,Openstreetmap,我是OpenStreetMap的新手,我一直在浏览wiki和网络,似乎在任何地方都找不到教程,但我在网上看到了一些例子 基本上,我想生成自己的OpenStreetmap和绘图标记,从MySQL数据库中获取纬度和经度,并在地图上绘图。当用户点击一个标记时,我想弹出一个窗口。基本上,我想要的是OpenStreetMap,而不是Google地图。看起来他们正在使用地图渲染。下面是一些示例和api文档 看起来它们正在用于地图渲染。下面是一些示例和api文档 要实现这一点,您需要找出在“slippy

我是OpenStreetMap的新手,我一直在浏览wiki和网络,似乎在任何地方都找不到教程,但我在网上看到了一些例子

基本上,我想生成自己的OpenStreetmap和绘图标记,从MySQL数据库中获取纬度和经度,并在地图上绘图。当用户点击一个标记时,我想弹出一个窗口。基本上,我想要的是OpenStreetMap,而不是Google地图。

看起来他们正在使用地图渲染。下面是一些示例和api文档

看起来它们正在用于地图渲染。下面是一些示例和api文档


要实现这一点,您需要找出在“slippy map”界面上显示标记的javascript

OpenLayers是一个流行的javascript库的名称。它是免费的,开源的。它被用来在OpenStreetMap.org主页和其他网站上显示一张拖沓的地图。它经常与OpenStreetMap本身相混淆,或者人们错误地认为如果你想在你的网站上嵌入OpenStreetMap地图,就必须使用OpenLayers。不是真的。有

…包括谷歌地图API!您可以设置google地图显示,但显示OpenStreetMap“平铺”图像而不是google平铺。看见这具有代码兼容性的优势,这意味着您可以按照链接到那里的google地图教程进行操作,但随后插入一段厚脸皮的代码,将OpenStreetMap指定为平铺层

这样做的缺点是显示一个巨大的邪恶谷歌徽标,并且需要一个更邪恶的谷歌地图API键,因此所有酷孩子都在使用OpenLayers

有一个。“OpenLayers Dynamic POI”示例展示了数据库对标记的使用(尽管该示例有点复杂)


希望这有助于

实现这一点,您需要找出在“拖拉地图”界面上显示标记的javascript

// Sample code by August Li
// Modified by Tom Moore to work with SQL
var zoom, center, currentPopup, map, lyrMarkers;
var popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    "autoSize": true,
    "minSize": new OpenLayers.Size(300, 50),
    "maxSize": new OpenLayers.Size(500, 300),
    "keepInMap": true
});
var bounds = new OpenLayers.Bounds();
var lat=36.287179515680556;
var lon=-96.69170379638672;
var zoom=11;
var lonLat = new OpenLayers.LonLat(lon, lat).transform(
                 new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));

// begin addMarker function
// info1 I was going to use to add a tooltip. Haven't figured out
// how to do that in OpenLayers yet :( Someone who knows share that with us
// iconurl is the url to the png file that you want to use for the icon.
// you MUST call addMarker at least once to initialize the map
function addMarker(lat, lng, info, info1, iconurl) {
    // First check to see if the map has been initialized. If not, do that now ...
    if (map == null) {
        var options = {
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),
            units: "m",
            numZoomLevels: 19,
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)
        };
        map = new OpenLayers.Map("map", options);
        map.addControl(new OpenLayers.Control.PanZoomBar());
        var lyrOsm = new OpenLayers.Layer.OSM();
        map.addLayer(lyrOsm);
        lyrMarkers = new OpenLayers.Layer.Markers("Markers");
        map.addLayer(lyrMarkers);

        //add marker on given coordinates
        map.setCenter(lonLat, zoom);
        zoom = map.getZoom();
    }

    var iconSize = new OpenLayers.Size(36, 36);
    var iconOffset = new OpenLayers.Pixel(-(iconSize.w / 2), -iconSize.h);
    var icon = new OpenLayers.Icon(iconurl, iconSize, iconOffset);
    var pt = new OpenLayers.LonLat(lng, lat).transform(
                 new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    bounds.extend(pt);
    var feature = new OpenLayers.Feature(lyrMarkers, pt);
    feature.closeBox = true;
    feature.popupClass = popupClass;
    feature.data.popupContentHTML = info;
    feature.data.overflow = "auto";
    var marker = new OpenLayers.Marker(pt, icon.clone());
    var markerClick = function(evt) {
        if (currentPopup != null && currentPopup.visible()) {
            currentPopup.hide();
        }
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        currentPopup = this.popup;
        OpenLayers.Event.stop(evt);
    };
    marker.events.register("mousedown", feature, markerClick);
    lyrMarkers.addMarker(marker);
}
// end addMarker function
OpenLayers是一个流行的javascript库的名称。它是免费的,开源的。它被用来在OpenStreetMap.org主页和其他网站上显示一张拖沓的地图。它经常与OpenStreetMap本身相混淆,或者人们错误地认为如果你想在你的网站上嵌入OpenStreetMap地图,就必须使用OpenLayers。不是真的。有

…包括谷歌地图API!您可以设置google地图显示,但显示OpenStreetMap“平铺”图像而不是google平铺。看见这具有代码兼容性的优势,这意味着您可以按照链接到那里的google地图教程进行操作,但随后插入一段厚脸皮的代码,将OpenStreetMap指定为平铺层

这样做的缺点是显示一个巨大的邪恶谷歌徽标,并且需要一个更邪恶的谷歌地图API键,因此所有酷孩子都在使用OpenLayers

有一个。“OpenLayers Dynamic POI”示例展示了数据库对标记的使用(尽管该示例有点复杂)

希望有帮助

// Sample code by August Li
// Modified by Tom Moore to work with SQL
var zoom, center, currentPopup, map, lyrMarkers;
var popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    "autoSize": true,
    "minSize": new OpenLayers.Size(300, 50),
    "maxSize": new OpenLayers.Size(500, 300),
    "keepInMap": true
});
var bounds = new OpenLayers.Bounds();
var lat=36.287179515680556;
var lon=-96.69170379638672;
var zoom=11;
var lonLat = new OpenLayers.LonLat(lon, lat).transform(
                 new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));

// begin addMarker function
// info1 I was going to use to add a tooltip. Haven't figured out
// how to do that in OpenLayers yet :( Someone who knows share that with us
// iconurl is the url to the png file that you want to use for the icon.
// you MUST call addMarker at least once to initialize the map
function addMarker(lat, lng, info, info1, iconurl) {
    // First check to see if the map has been initialized. If not, do that now ...
    if (map == null) {
        var options = {
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),
            units: "m",
            numZoomLevels: 19,
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)
        };
        map = new OpenLayers.Map("map", options);
        map.addControl(new OpenLayers.Control.PanZoomBar());
        var lyrOsm = new OpenLayers.Layer.OSM();
        map.addLayer(lyrOsm);
        lyrMarkers = new OpenLayers.Layer.Markers("Markers");
        map.addLayer(lyrMarkers);

        //add marker on given coordinates
        map.setCenter(lonLat, zoom);
        zoom = map.getZoom();
    }

    var iconSize = new OpenLayers.Size(36, 36);
    var iconOffset = new OpenLayers.Pixel(-(iconSize.w / 2), -iconSize.h);
    var icon = new OpenLayers.Icon(iconurl, iconSize, iconOffset);
    var pt = new OpenLayers.LonLat(lng, lat).transform(
                 new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    bounds.extend(pt);
    var feature = new OpenLayers.Feature(lyrMarkers, pt);
    feature.closeBox = true;
    feature.popupClass = popupClass;
    feature.data.popupContentHTML = info;
    feature.data.overflow = "auto";
    var marker = new OpenLayers.Marker(pt, icon.clone());
    var markerClick = function(evt) {
        if (currentPopup != null && currentPopup.visible()) {
            currentPopup.hide();
        }
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        currentPopup = this.popup;
        OpenLayers.Event.stop(evt);
    };
    marker.events.register("mousedown", feature, markerClick);
    lyrMarkers.addMarker(marker);
}
// end addMarker function
致以最良好的祝愿!我希望这能帮助那些需要它的人

致以最良好的祝愿!我希望这能帮助那些需要它工作的人…

是的。“OpenLayers”是OpenStreetMap.org主页上使用的slippy map javascript库。术语“渲染”通常用于过程的不同部分(从基础地图数据创建光栅地图图形)是的。“OpenLayers”是OpenStreetMap.org主页上使用的slippy map javascript库。术语“渲染”通常用于过程的不同部分(从基础地图数据创建光栅地图图形)