Siema wszystkim mam pytanie odnośnie dostępu do metody give(), próbowałem się wcześniej dostać do niej metodą bind() z poziomu listenera ale coś mi nie wychodziło.Poniżej kod:
constructor(radius_circle) {
this.radius_circle = radius_circle;
}
toString(rad) {
this.radius_circle=rad;
}
give()
{
return this.radius_circle;
}
makeMap() {
var mapa;
var geokoder;
var dymek;
var circle;
var markers_on_map = [];
var all_locations = [
{type: "Restaurant", name: "Restaurant 1", lat: 40.723080, lng: -73.984340},
{type: "School", name: "School 1", lat: 40.724705, lng: -73.986611},
{type: "School", name: "School 2", lat: 40.724165, lng: -73.983883},
{type: "Restaurant", name: "Restaurant 2", lat: 40.721819, lng: -73.991358},
{type: "School", name: "School 3", lat: 40.732056, lng: -73.998683}
];
var loc = this.location.split(","),
pos = new google.maps.LatLng(loc[0], loc[1]);
var mapOptions =new google.maps.Map(document.querySelector("#map"), {
zoom: 11,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions:
{
position: google.maps.ControlPosition.BOTTOM_LEFT
}
});
mapa = new google.maps.Map(document.getElementById("map"), mapOptions);
geokoder = new google.maps.Geocoder();
dymek = new google.maps.InfoWindow();
google.maps.event.addListener(mapa,'dragend',function(zdarzenie)
{
//console.log(this.give());
var mylat=mapa.getCenter().lat();
var mylng=mapa.getCenter().lng();
var i;
var address = $('#address').val();
if (circle) {
circle.setMap(null);
circle = null;
}
for (i = 0; i < markers_on_map.length; i++) {
if (markers_on_map[i]) {
markers_on_map[i].setMap(null);
markers_on_map[i] = null;
}
}
if (geokoder) {
geokoder.geocode({'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
var address_lat_lng = results[0].geometry.location;
circle = new google.maps.Circle({
map: mapa,
position: new google.maps.LatLng(mylat, mylng),
radius: this.give(),//w tym miejscu powinna być wyciągnięta wartość z funkcji
strokeColor: '#b2dae8',
strokeOpacity: 0.8,
strokeWeight: 2,
clickable: false,
fillColor: '#b2dae8',
fillOpacity: 0.35
});
circle.bindTo('center', circle, 'position');
for (var j = 0; j < all_locations.length; j++) {
(
function (location) {
var marker_lat_lng = new google.maps.LatLng(location.lat, location.lng);
var distance_from_location = google.maps.geometry.spherical.computeDistanceBetween(new google.maps.LatLng(mylat, mylng), marker_lat_lng);
if (distance_from_location <= this.give()) {//w tym miejscu powinna być wyciągnięta wartość z funkcji
var new_marker = new google.maps.Marker({
position: marker_lat_lng,
map: mapa,
title: location.name
});
Może wyglądać skomplikowanie ale tylko chodzi o to żeby wyciągnać z funkcji give() wcześniej zapisaną wartość w miejscu gdzie próbowałem to wyciągnać czyli gdzie jest napisane this.give wewnątrz listenera "google.maps.event.addListener" męczyłem się z tym dwie godziny i wyskauje mi ten sam błąd "this.give is not a function" bardzo proszę o pomoc ja już nie mam na to siły
Problem rozwiązany!!!!!!!! wystarczyło podl listenerem w miejscu console loga wpisać "var self=this" i następnie w miejscach this.give() słowko this zastąpić słówkiem self, mam nadzieję że komuś się to przyda