如何在javascript中访问我的点?
当我将代码从google maps v2迁移到v3时,我想知道当我可以让警报符号写入调试信息时,如何访问地图上的点击点,我想访问地图上的点击点:如何在javascript中访问我的点?,javascript,google-maps-api-3,Javascript,Google Maps Api 3,当我将代码从google maps v2迁移到v3时,我想知道当我可以让警报符号写入调试信息时,如何访问地图上的点击点,我想访问地图上的点击点: google.maps.event.addListener(map, "click", gAdd); 我的相关代码: function gAdd(overlay, latlng) { alert("test"+overlay); if (latlng != null) { alert("test");
google.maps.event.addListener(map, "click", gAdd);
我的相关代码:
function gAdd(overlay, latlng) {
alert("test"+overlay);
if (latlng != null) {
alert("test");//address = latlng;
try {
alert("test");//geocoder.getLocations(latlng, gDisplay);
} catch (e) {}
}
}
function initialize() {
document.upload.lat.value = geoip_latitude();
document.upload.lng.value = geoip_longitude();
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(geoip_latitude(), geoip_longitude());
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: 'roadmap'
}
map = new google.maps.Map(document.getElementById("gmap"), myOptions);
google.maps.event.addListener(map, "click", gAdd);
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById("message").innerHTML = results[5].formatted_address;
} else {
}
});
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var latlng = initialLocation
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent('<a href="/li?lat=' + latlng.lat() + '&lon=' + latlng.lng() + '">' + results[1].formatted_address + '</a>');
infowindow.open(map, marker);
document.upload.lat.value = latlng.lat();
document.upload.lng.value = latlng.lng();
document.upload.place.value = results[5].formatted_address
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}, function () {
handleNoGeolocation(browserSupportFlag);
});
} else if (google.gears) {
// Try Google Gears Geolocation
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.latitude, position.longitude);
//contentString = "Location found using Google Gears";
var latlng = initialLocation
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
//map.setZoom(11);
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent('<a href="/li?lat=' + latlng.lat() + '&lon=' + latlng.lng() + '">' + results[1].formatted_address + '</a>');
infowindow.open(map, marker);
document.upload.lat.value = latlng.lat();
document.upload.lng.value = latlng.lng();
//alert('6 '+results[6].formatted_address );
document.upload.place.value = results[5].formatted_address;
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}, function () {
handleNoGeolocation(browserSupportFlag);
});
} else {
// Browser doesn't support Geolocation
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
功能gAdd(覆盖、板条){
警报(“测试”+叠加);
如果(latlng!=null){
警报(“测试”);//地址=latlng;
试一试{
警报(“测试”);//geocoder.getLocations(latlng、gDisplay);
}捕获(e){}
}
}
函数初始化(){
document.upload.lat.value=geoip_lation();
document.upload.lng.value=geoip_longitude();
geocoder=新的google.maps.geocoder();
var latlng=new google.maps.latlng(geoip_纬度(),geoip_经度());
变量myOptions={
缩放:8,
中心:拉特林,
mapTypeId:“路线图”
}
map=新的google.maps.map(document.getElementById(“gmap”),myOptions);
google.maps.event.addListener(映射,“单击”,gAdd);
地理编码({
“latLng”:latLng
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
document.getElementById(“message”).innerHTML=results[5]。格式化的地址;
}否则{
}
});
if(导航器.地理位置){
browserSupportFlag=true;
navigator.geolocation.getCurrentPosition(函数(位置){
initialLocation=new google.maps.LatLng(position.coords.lation,position.coords.longitude);
var latlng=初始位置
地理编码({
“latLng”:latLng
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
如果(结果[1]){
marker=新的google.maps.marker({
位置:latlng,
地图:地图
});
infowindow.setContent(“”);
信息窗口。打开(地图、标记);
document.upload.lat.value=latlng.lat();
document.upload.lng.value=latlng.lng();
document.upload.place.value=结果[5]。格式化的\u地址
}否则{
警报(“未发现结果”);
}
}否则{
警报(“地理编码器因“+状态”而失败);
}
});
},函数(){
handleNoGeolocation(浏览器支持标志);
});
}else if(google.gears){
//试试谷歌齿轮地理定位
browserSupportFlag=true;
var geo=google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(函数(位置){
initialLocation=new google.maps.LatLng(位置.纬度,位置.经度);
//contentString=“使用Google Gears找到的位置”;
var latlng=初始位置
地理编码({
“latLng”:latLng
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
如果(结果[1]){
//map.setZoom(11);
marker=新的google.maps.marker({
位置:latlng,
地图:地图
});
infowindow.setContent(“”);
信息窗口。打开(地图、标记);
document.upload.lat.value=latlng.lat();
document.upload.lng.value=latlng.lng();
//警报('6'+结果[6]。格式化的地址);
document.upload.place.value=结果[5]。格式化的\u地址;
}否则{
警报(“未发现结果”);
}
}否则{
警报(“地理编码器因“+状态”而失败);
}
});
},函数(){
handleNoGeolocation(浏览器支持标志);
});
}否则{
//浏览器不支持地理位置
browserSupportFlag=false;
handleNoGeolocation(浏览器支持标志);
}
这曾经适用于google maps v2,现在我想将其迁移到v3。单击处理程序在v3中获得一个事件对象,坐标位于:
function gAdd(ev) {
var latlng = ev.latLng;
//...
}