gpt4 book ai didi

javascript - PhoneGap/ Cordova : Google Maps API - drop pin on my position

转载 作者:行者123 更新时间:2023-11-29 18:27:18 26 4
gpt4 key购买 nike

我可以在 PhoneGap 中使用 Google Maps API 在 map 上显示我的位置。现在它只显示 map - 没有 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);

如果有人能告诉我如何在那个位置放置图钉,那就太棒了!谢谢

最佳答案

找到了! 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);

关于javascript - PhoneGap/ Cordova : Google Maps API - drop pin on my position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com