2

我可以在 PhoneGap 中使用 Google Maps API 在地图上显示我的位置。现在它只显示地图 - 没有 pindrop 或类似的东西。我想知道是否有人知道如何在您提出的位置上放置图钉?

我到目前为止的代码是:

//GEOLOCATION
            var onSuccess = function(position) {
                var myLat = position.coords.latitude;
                var myLong = position.coords.longitude;

                //MAP
                var mapOptions = {
                    center: new google.maps.LatLng(myLat, myLong),
                    zoom: 14,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

            var map = new google.maps.Map(document.getElementById("map_canvas"),
                                              mapOptions);

            };

            // onError Callback receives a PositionError object
            //
            function onError(error) {
                alert('code: '    + error.code    + '\n' +
                      'message: ' + error.message + '\n');
            }

            navigator.geolocation.getCurrentPosition(onSuccess, onError);

如果有人能告诉我如何在那个位置放一个大头针,那真是太棒了!谢谢

4

1 回答 1

4

找到了!https://developers.google.com/maps/documentation/javascript/overlays#Markers

调整了我的代码:

//GEOLOCATION
            var onSuccess = function(position) {
                var myLat = position.coords.latitude;
                var myLong = position.coords.longitude;

                //MAP
                var mapOptions = {
                    center: new google.maps.LatLng(myLat, myLong),
                    zoom: 14,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };

            var map = new google.maps.Map(document.getElementById("map_canvas"),
                                              mapOptions);

                var marker = new google.maps.Marker({
                                                    position: new google.maps.LatLng(myLat, myLong),
                                                    map: map,
                                                    title:"Hello World!"
                                                    });

            };

            // onError Callback receives a PositionError object
            //
            function onError(error) {
                alert('code: '    + error.code    + '\n' +
                      'message: ' + error.message + '\n');
            }

            navigator.geolocation.getCurrentPosition(onSuccess, onError);
于 2012-08-01T06:35:40.950 回答