R
R
Rodion Yurchenko2016-05-22 15:30:24
JavaScript
Rodion Yurchenko, 2016-05-22 15:30:24

Need to embed a google map on the site with a search on it and the ability to leave a marker?

Good afternoon!
Actually there is a map with a search - below is the code
But here you need to somehow tie the ability to put AND MOVE (drag / drop) 1 marker
If anyone is too lazy to copy the code or some problems with the code itself - then here is the source - where did I get it from: click

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAACHCJdlgAEGcD_flKUFEmVhQlAYd20Yeej0MiKNuYPUGBnCwDThQlwUCPtCqtX3RC7LUKE-JYan3T4g" type="text/javascript"></script>
    <script type="text/javascript">
        var map = null;
        var geocoder = null;
        function initialize() {
            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map_canvas"));
                map.setCenter(new GLatLng(56.32811,44.0), 13);
                geocoder = new GClientGeocoder();
            }
        }
        function showAddress(address) {
            console.log(geocoder);
            if (geocoder) {
                geocoder.getLatLng(
                    address,
                    function(point) {
                        if (!point) {
                            alert(address + " not found");
                        } else {
                            map.setCenter(point, 17);
                            var marker = new GMarker(point);
                            map.addOverlay(marker);
                            marker.openInfoWindowHtml(address);
                        }
                    }
                );
            }
        }
    </script>

<body onload="initialize()" onunload="GUnload()">
<form action="#" onsubmit="showAddress(this.address.value); return false">
    <p>
        <input type="text" size="60" name="address" value="Нижний Новгород, ул. Белинского, 59" />
        <input type="submit" value="Найти" />
    </p>
    <div id="map_canvas" style="width: 800px; height: 600px"></div>
</form>
</body>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2016-05-22
@aassdds

Markers have a draggable property , which is probably what you want. I sketched a small example . Not the same as yours, but the idea is the same - in the search (top right) an address is searched, a marker is put in place of this address, which can then be moved (coordinates at the bottom left)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question