Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Marker - Google Map (Simple) - Google Javascript API #18

Open
haiquang9994 opened this issue Apr 5, 2016 · 1 comment
Open

Add Marker - Google Map (Simple) - Google Javascript API #18

haiquang9994 opened this issue Apr 5, 2016 · 1 comment
Labels

Comments

@haiquang9994
Copy link

Vào trang Console Google API để tạo API Key.
Tạo một project mới.
Enable API cần dùng. Google Maps JavaScript API
Trong tab Credentials tạo mới một API Key.


Thư viện Google Javascript API

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=[YOUR_KEY]&signed_in=true&callback=initMap" async defer></script>

Tạo mới map.

<div id="map_canvas"></div>
function initMap(){
           var map = new google.maps.Map(document.getElementById('map_canvas'), {
                center: {
                    lat: 10.825,
                    lng: 106.685
                },
                zoom: 15
            });
}

Hàm xử lý.

        function geocoderAddress(geocoder, resultsMap, address) {
            geocoder.geocode({
                address: address
            }, function (results, status) {
                if (status === google.maps.GeocoderStatus.OK) {
                    resultsMap.setCenter(results[0].geometry.location);
                    if (marker) {
                        marker.setMap(null);
                    }
                    marker = addMarker(resultsMap, results[0].geometry.location);
                }
            });
        }

        function addMarker(map, position) {
            var mk = new google.maps.Marker({
                map: map,
                position: position
            });
            return mk;
        }

Tạo Marker.

var geocoder = new google.maps.Geocoder();
var address = "07 Nam Quoc Cang, Phuong Pham Ngu Lao, Quan 1, TP Ho Chi Minh";
geocoderAddress(geocoder, map, address);
@khanhicetea
Copy link
Contributor

Good

Good job !!!

@khanhicetea khanhicetea added the js label Apr 5, 2016
@haiquang9994 haiquang9994 changed the title Add Marker (Simple) - Google Javascript API Add Marker (Simple) - Google Map Javascript API May 5, 2016
@haiquang9994 haiquang9994 changed the title Add Marker (Simple) - Google Map Javascript API Add Marker - Google Map (Simple) - Google Javascript API May 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants