Skip to content

Instantly share code, notes, and snippets.

<script>
export default {
data() {
return {
lat: 0,
lng: 0,
type: "",
radius: "",
places: []
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<img src="https://via.placeholder.com/150" />
const URL = `https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${
this.lat
},${this.lng}&type=${this.type}&radius=${this.radius * 1000}&key=${
this.apiKey
}`;
axios
.get(URL)
.then(response => {
console.log(response);
import UIKit
class ViewController: UIViewController{
private let latLngLabel: UILabel = {
let label = UILabel()
label.backgroundColor = .systemFill
label.numberOfLines = 0
label.textAlignment = .center
label.font = .systemFont(ofSize: 26)
<template>
<div class="ui grid">
<div class="six wide column"></div>
<div class="ten wide column segment ui" ref="map"></div>
</div>
</template>
<div class="six wide column">
<form class="ui segment large form">
<div class="ui segment">
<div class="field">
<div class="ui right icon input large">
<input type="text" placeholder="Enter your address" v-model="coordinates" />
<i class="dot circle link icon" @click="locatorButtonPressed"></i>
</div>
</div>
<div class="field">
data() {
return {
lat: 0,
lng: 0,
type: "",
radius: "",
places: []
};
},
computed: {
methods: {
locatorButtonPressed() {
navigator.geolocation.getCurrentPosition(
position => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
},
error => {
console.log("Error getting location");
}
findCloseBuyButtonPressed() {
const URL = `https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${
this.lat
},${this.lng}&type=${this.type}&radius=${this.radius *
1000}&key=[YOURAPIKEY]`;
axios
.get(URL)
.then(response => {
this.places = response.data.results;
this.addLocationsToGoogleMaps();
<div class="ui segment" style="max-height:500px;overflow:scroll">
<div class="ui divided items">
<div class="item" v-for="place in places" :key="place.id">
<div class="content">
<div class="header">{{place.name}}</div>
<div class="meta">{{place.vicinity}}</div>
</div>
</div>
</div>
</div>