gpt4 book ai didi

javascript - 从 GWT 调用框架 js

转载 作者:行者123 更新时间:2023-12-03 04:32:03 24 4
gpt4 key购买 nike

我正在尝试从 GWT 调用框架 js。

我的java代码是:

 public class Trips extends MyPopup{
Frame f = new Frame("js/location.html")

public popupPanel(){
super() ;
setAddress(0d,0d,"asknjsnkjsd") ;

}
//other methods.object of this class is created while loading

public static native void setAddress(Double lat,Double longitude,String address) /*-{
$wnd.alert(address);
$wnd.setAddress(lat,longitude,address) ;
}-*/;

}

我的js代码是:

 var map ;
var marker ;

function initMap() {
var locat = new google.maps.LatLng(parseFloat("34.149486"),parseFloat("-117.257317"));

map = new google.maps.Map(document.getElementById('map'), {
center : {
lat : 34.149486,
lng : -117.257317
},
zoom : 13
});

myMap = map;


marker = new google.maps.Marker({
position : {
lat : 34.149486,
lng : -117.257317
},
map : map,
draggable : true,
anchorPoint : new google.maps.Point(0, -29)
});

myMarker = marker ;

var geocoder = geocoder = new google.maps.Geocoder();

var card = document.getElementById('pac-card');
var input = document.getElementById('pac-input');
var strictBounds = document.getElementById('strict-bounds-selector');

map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);

var autocomplete = new google.maps.places.Autocomplete(input);

// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
autocomplete.bindTo('bounds', map);

var infowindow = new google.maps.InfoWindow();
var infowindowContent = document.getElementById('infowindow-content');
infowindow.setContent(infowindowContent);

google.maps.event
.addListener(
marker,
"dragend",
function(e) {
var lat, lng, address;

geocoder
.geocode(
{
'latLng' : marker.getPosition()
},
function(results, status) {
document
.getElementById('pac-input').value = results[0].formatted_address;
var latitide = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
var addressLocation = results[0].formatted_address;
});
});

autocomplete.addListener('place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window
.alert("No details available for input: '" + place.name
+ "'");
return;
}

// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);

var address = '';
var latitide = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var addressLocation = place.formatted_address;
if (place.address_components) {
address = [
(place.address_components[0]
&& place.address_components[0].short_name || ''),
(place.address_components[1]
&& place.address_components[1].short_name || ''),
(place.address_components[2]
&& place.address_components[2].short_name || '') ]
.join(' ');
}

infowindowContent.children['place-icon'].src = place.icon;
infowindowContent.children['place-name'].textContent = place.name;
infowindowContent.children['place-address'].textContent = address;
infowindow.open(map, marker);
});

// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
}

function setOriginAddressWithLatitude(lat,long,address){
window
.alert("No details available for input: '" + lat + " " + long +" " + address
+ "'");

document.getElementById('pac-input').value = address;
//initMap() ;
map.setCenter(new google.maps.LatLng(lat,long));
marker.setPosition(new google.maps.LatLng(lat,long));

}

html 文件是:

<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?key=API_Key&libraries=places&callback=initMap"
async defer></script>
<script src = "location.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">

</head>
<body>
<div class="pac-card" id="pac-card">
<div id="pac-container">
<input id="pac-input" type="text"
placeholder="Enter a location" value = "St Marys Rd Sydney NSW 2000 Australia">
</div>
</div>
<div id="map"></div>
<div id="infowindow-content">
<img src="" width="16" height="16" id="place-icon">
<span id="place-name" class="title"></span><br>
<span id="place-address"></span>
</div>
</body>
</html>

我在此遇到以下错误 无法将属性“value”设置为 null 在线 document.getElementById('pac-input').value = address;

如果我删除上面的行。我收到错误ma​​p.setCenter不是一个函数

最佳答案

我使用了以下内容

public native void setOriginAddressWithLatitude(Double latitude,Double longitude,String address) /*-{
var iframe = $doc.getElementById("viewMapIFrame");
iframe.contentWindow.setOriginAddressWithLatitude(latitude,longitude,address) ;
}-*/;

关于javascript - 从 GWT 调用框架 js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43450363/

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