How can I adjust the radius of the Google Places service in real-time?

When I input a value such as 1000 in the text field, I want to dynamically change the radius in the request variable. For example, if I enter 1000 meters, only parking areas within that radius should be visible. Similarly, entering another value should dynamically adjust the radius.

<!DOCTYPE html>
<html>
<head>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=true&libraries=places">    </script>
<script>
var marker;
var map;
var infowindow = new google.maps.InfoWindow();
var myCenter;
var markers = [];

function initialize() 
{
    myCenter = new google.maps.LatLng(13.052413899999994,80.25065293862303);        
    map = new google.maps.Map(document.getElementById('map-canvas'), {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: myCenter,
        zoom: 15
    });
}

function some()
{
    var request = {
    location: myCenter,
    radius: 500,
    types: ['bank']
    };

var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);

function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
        for (var i = 0; i < markers.length; i++) {
           markers[i].setMap(null);
                }
            markers = [];
        for (var i = 0; i < results.length; i++) {
        createMarker(results[i]);
        }
    }
}
function createMarker(place)
{
var placeLoc = place.geometry.location;
marker = new google.maps.Marker({
    position: place.geometry.location
});
marker.setIcon({
    url:'bank.png',
    size: new google.maps.Size(70, 71),
    anchor: new google.maps.Point(17, 14),
    scaledSize: new google.maps.Size(35, 35)
    });
marker.setMap(map);

google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
});
markers.push(marker);
}
}
google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas" style="width: 50%; float:left"></div>
<div style="width:46%; float:left">
<input type="number" id="inputarea">
<button onclick="some();">Banks</button>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> 
</script> 
<script type="text/javascript"> 
_uacct = "UA-162157-1";
urchinTracker();
</script> 
</body>
</html>

Answer №1

This is how you can achieve it:

const fetchData = async () => {
  try {
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    
    return data;
  } catch (error) {
    console.error(error);
  }
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty assigning a selected value in select2 using JavaScript with Ajax mode

I am trying to use a select2 element that loads data from a database using ajax. My goal is to load the value from the database and have it selected as the default value in edit mode. However, I am encountering issues with using the trigger function to ach ...

Mocking objects in unit test cases to simulate real-life scenarios and test the

How do I pass a mocked event object and ensure it is validated? onCallFunction() { const eventValue = event; if (!eventValue.relatedTarget || !eventValue.relatedTarget.last.contain('value')) { super.onCallFuncti ...

Regular expression for textarea validation

I'm currently working on creating a regex for a textarea in my Angular 8 application. The goal is to allow all characters but not permit an empty character at the start. I've experimented with 3 different regex patterns, each presenting its own s ...

Express.js: Exciting Outcomes

Currently diving into Express JS starting from scratch with the ultimate goal of mastering both Node and Express. While experimenting with some online examples, I stumbled upon an intriguing situation. Working on a basic http server, the code goes as foll ...

Revamp your array elements with MongoDB - Substring replacement

Having some difficulty replacing a substring within various documents. Below is an example of one such document: { "images" : [ { "url" : "https://example/1234" }, { "url" : "https://example/afaef" }, { "url" : ...

Google Script: Implementing multiple conditions based on unique identifiers

A custom script has been designed to keep track of the frequency of VIN numbers repetitions and the status of parts arrival for each unique VIN Number (Car). For instance, if a VIN number appears 5 times, it indicates that five parts are expected to arriv ...

Unable to display the response received in jQuery due to a technical issue with the JSON data

Hey there! I'm fairly new to JSON and web development, so please bear with me if I'm not explaining the problem in the most technical terms. I recently encountered an issue where I retrieved a JSON response from a website, but I couldn't di ...

Setting HTML in the title for the list view in fullcalendar.js version 4

Received the following information from a source, but was unable to leave a comment due to insufficient points. Looking for assistance on setting HTML in title using fullcalendar.js v4 eventRender: function(info) { info.el.querySelector('.fc-titl ...

Creating dynamic routes in React by pulling data from a JSON file

Creating multiple routes based on JSON data file is the goal: routes.jsx import React from 'react'; import { Route, Router, IndexRoute } from 'react-router'; import ReactDOM from 'react-dom'; import App from './index.j ...

Steps for retrieving JSON data successfully following an asynchronous AJAX request in JavaScript

When submitting a form using AJAX, I need to pass successful data back to the submission page. The transaction is being sent over the TRON network, and the response is an array containing the transaction ID that needs to be returned to the submission page. ...

Embedding JQuery within a PHP file

Recently, our inventory web page was coded in PHP by someone else. I've been working on integrating a jQuery function into the webpage that displays a description whenever a barcode is scanned. While testing on jsbin.com everything works perfectly, bu ...

Flames dancing - transmitting parameter through callback feature

I am working on a code where I pass a function from javascript exportManager.RegisterCallbacks(function(progress) { console.log("export prog " + progress); }, function() { ...

Issue with submitting form in React when state changes upon button click event

I have created a button group to filter the table. The button group changes the color of the active button when clicked. To allow for multiple button groups for filtering, I decided to wrap the table and button group in a form element. However, when I clic ...

I'm struggling to connect the output of my Button to my JavaScript function

I have been working on a new feature for my website and encountered an issue with a JavaScript function. The goal is to enable disabled input boxes when the user clicks on a "yes" button. Unfortunately, clicking the "yes" button doesn't seem to be tr ...

Is there a way to verify if JQuery libraries (and other files containing custom code) have been properly included?

So I've got this JavaScript file with some code that relies on JQuery libraries. How can I make sure that both the file and the libraries are properly included? (I hope this question isn't too silly.) ...

What is the best way to check if a specific value is present in a JavaScript Array using a Function?

When a person uses an input field to type in a value, I have created the variable 'Ben' for that purpose. My goal is for a function to loop through the nameArray and return either true or false. Unfortunately, the script I've written isn& ...

What makes $http in AngularJs so unique that it can be thought of as both an object and a

Did you know that the $http service can be utilized in two distinct ways? Firstly, as a function, by using var promise = $http(config);. Here, the config object contains details about the http method and url. Alternatively, as an object, using $http ...

Error in Vue.js: Trying to access properties of an undefined object

My understanding of vue.js is limited, but based on what I know, this code should work. However, when attempting to access the variable in the data property, it seems unable to locate it. data: function() { return { id: 0, clients: [] ...

Contrast between the expressions '$(<%= DDL.ID %>) and $('<%= DDL.ID %>')

I spent hours trying to attach an event to a drop-down list with no success. I even sought help in a JavaScript chat room, but couldn't find a solution. However, by randomly attempting the following code: $('<%= ddl.ID %>').bind(&apos ...

The official sign-in buttons for Facebook, Google, and Twitter are all neatly aligned on the same row with a sleek and

https://i.sstatic.net/bXOMb.pngHello, I am currently working on integrating social media sign up functionality into my Oracle Apex login page. To achieve this, I am utilizing JavaScript APIs for various social media applications. However, I'm facing a ...