Is there a way to easily transfer your home address to Google Maps without having to manually input

Is there a way to automatically display home addresses directly on Google Maps (maps.google.com) and show it in the search bar of Google Maps using pure JAVASCRIPT, pulling the addresses from another website (UAT)? I'm new to this programming language, so any help would be greatly appreciated. Thank you!

For example:

Imagine there's a text field for entering a home address on another website, and the address inputted is:

345 Bury Village Oslo St. Bershka City, Switzerland

I want to copy/display this entire home address on Google Maps and have it automatically searched.

Here's the code snippet I am currently using:

function scanLapVerification() {
try {
    // Code logic here for reading and extracting address details
}
// Additional code logic for opening Google Maps in a new tab and entering the full address into search input needed here
        }
    return { status: "KO" };
} catch (e) {
        alert("Exception: scanLapVerification\n" + e.Description);
    return { status: "KO", message: e };
}
};

Answer №1

Link to JSFiddle
To implement this feature, you will need to utilize geocoding service. Here is an example of how it can be achieved:

HTML

<input id="address" value="Volgograd, Mamayev Kurgan" /><button type="button" onclick="geocode();">Search</button><button type="button" onclick="searchWithoutGmap();">Search without GMap</button>
<div id="map"></div>
<div id="output"></div>

CSS

div#map {
    width: 400px;
    height: 300px;
}

JS

var map;
var marker;
var geocoder;
$( function() {
    map = new google.maps.Map( $( "div#map" )[ 0 ], {
        center: new google.maps.LatLng( 48.7, 44.516 ),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    } );
    geocoder = new google.maps.Geocoder();
} );
function geocode() {
    var address = $( "input#address" ).val();
    geocoder.geocode( { 'address': address }, function ( results, status ) {
        if ( status == google.maps.GeocoderStatus.OK ) {
            // handle the results accordingly
            console.log( results );
            // move to the first result
            map.panTo( results[ 0 ].geometry.location );
            // display or update marker
            if ( marker ) {
                marker.setPosition( results[ 0 ].geometry.location );
            } else {
                marker = new google.maps.Marker( {
                    position: results[ 0 ].geometry.location,
                    map: map
                } );
            }
            // adjust zoom level
            zoomToPan(16);
        } else if ( status == google.maps.GeocoderStatus.ZERO_RESULTS ) {
            alert( "Zero results." );
        }
    } );
}
function zoomToPan( level_to ) {
    var zoom = map.getZoom();
    if ( level_to != zoom ) {
        setTimeout( function( current_level_to, current_zoom ){
            return function(){
                if ( current_level_to < current_zoom ) {
                    map.setZoom( current_zoom - 1 );
                    zoomToPan( current_level_to );
                } else {
                    map.setZoom( current_zoom + 1 );
                    zoomToPan( current_level_to );
                }
            }
        }( level_to, zoom ), 80 );
    }
}
function searchWithoutGmap() {
    var address = $( "input#address" ).val();
    var format = "json";// xml
    var url = "http://maps.googleapis.com/maps/api/geocode/" + format + "?" + "sensor=false&address=" + address;
    $.ajax( {
        url: url,
        crossDomain: true,
        dataType: "json",
        success: function( data, textStatus, jqXHR ) {
            $( "div#output" ).html( JSON.stringify( data ) );
        }
    } );
}

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

Unable to load a different webpage into a DIV using Javascript

Today has been a bit challenging for me. I've been attempting to use JavaScript to load content into a <div>. Here is the JavaScript code I'm working with: function loadXMLDoc(filename) { var xmlhttp; if (window.XMLHttpRequest) { ...

Is there a way to extract both a and b from the array?

I just started learning programming and I'm currently working on creating an API call to use in another function. However, I've hit a roadblock. I need to extract values for variables a and b separately from the response of this API call: import ...

CORS headers present but AJAX request still fails

A request sent via AJAX from a locally hosted page to a remote server is encountering errors, despite the presence of CORS headers. The JavaScript code for this request is as follows: $.ajax({url: 'http://prox.tum.lt/420663719182/test-upload?Action=S ...

What is the best way to leverage a webbrowser control for design purposes while keeping the functionality in C#?

Observing some apps, it seems they utilize HTML/CSS/Javascript for styling - a much simpler approach compared to crafting the same thing natively. However, these apps have their logic written in C#. Sadly, I am clueless on connecting the two. Research yiel ...

Determining the type of <this> in an Object extension method using TypeScript

I am attempting to incorporate a functionality similar to the let scope function found in Kotlin into TypeScript. My current strategy involves using declaration merging with the Object interface. While this approach generally works, I find myself missing ...

How can I make my modal box appear after someone clicks on selecting a college?

Can someone help me figure out how to display my modal box after clicking into the selecting list? I've already coded it, but I'm struggling with getting it to show up after the click event. Any assistance is appreciated! In the image provided, ...

A step-by-step guide to parsing a JSON string with jQuery

Attempting to extract data from a JSON string using jQuery, but encountering issues with retrieving values. var jsonString = '{"data":{"2G":[{"amount":"9","detail":"35 MB 2G Data , Post 35 MB you will be charged at 4p\/10kb","validity":"1 Day"," ...

Prevent Object Prop Modification in Vue.js

Within the parent component, I initially have an empty filter object like this: {}. The child component, called filter component, is a child of the parent component and here's how it is implemented: <filter-component :filters.sync="filters&q ...

Learn how to dynamically activate an icon in Angular to enhance user interaction

HTML Code: The Zoom Component <div class="zoom py-3"> <i nz-icon nzType="minus" (click)="zoomToggle(false)" nzTheme="outline"></i><br> <i nz-icon nzType="plus" (click)=&q ...

Can one access console and localstorage through android studio?

Is there a way to detect if LocalStorage is being saved on an Android device from Android Studio in an application with a WebView? Also, can javascript code be executed from Android Studio similar to running it in a Chrome console? ...

The kendo-chart-tooltip script is causing an error by generating an Uncaught TypeError: background.isDark is not a recognized function

Click here for image descriptionHaving issues with the kendo-chart-tooltip functionality in my Angular 5 platform. The console shows a script error related to 'background.isDark' not being a function. zone.js:192 Uncaught TypeError: back ...

Using jQuery to target a specific HTML element by its ID, not requesting the entire webpage

Currently, I am attempting to utilize jQuery ajax to fetch a project page. In this scenario, the xhr variable is expected to hold the correct string to the webpage (the target page). I have set up a condition to prevent the page from loading as a mobile v ...

The issue of variable being undefined in JSON for JavaScript and Python

Consider a scenario where you have the following JSON object (remove the semicolon for python): values = { a: 1, b: { c: 2, d: { e: 3 } }, f: 4, g: 5 }; When attempting to print values in JavaScript, it will work pr ...

Guide to Aligning Divs at the Center in Bootstrap 4

I've been attempting to center the div on the page using Bootstrap 4, however, it's not cooperating. I've tried using the margin:0 auto; float:none property as well as the d-block mx-auto class, but neither are working. Below is my HTML code ...

Is it possible for us to implement a search feature similar to Google Now within our app?

Is there a way to incorporate Google Now features into our app? I am looking for a way to receive text or speech results for voice search within the app. So far, the closest option I have come across is RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE ...

When iterating through a loop, the final value in an array is often overlooked

I have been attempting to iterate through an array to determine if any of the values, when compared to all other values in the array using the modulo operation, do not return a 0. Essentially, this process should only return the prime numbers in the array ...

Implementing watch functionality with array in Vuejs for bidirectional communication between parent and child components

Here is a simplified version of a parent component I created: // parent component <template> <layout v-for="(value, idx) in array" :pickUpLength="array.length" :idx="idx" :key="idx" > <button @click="addArray">a ...

struggling to send variables to jade templates with coffeescript and express.js

As a newcomer to node and express, I am currently building the front end of an application that utilizes jade as its templating engine. Despite extensive searching online and within this community, I have not been able to find a solution to a particular is ...

What is the method for nesting data within a component's child>child>child structure?

In the structure I am working with, there is a hierarchy: Root component buttons (menu search component) - an input field for searching Widgets (widget component ) (Cats widget) - displays what is input in the menu search here. My challen ...

Utilize regular expressions on a JSON response dataset

Imagine a scenario where a client makes a GET request and the response is in JSON format similar to the following: var result = { "enabled": true, "state": "schedule", "schedules": [ { "rule": { "start": "2014-06-2 ...