Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
Cómo obtener la ubicación de los visitantes usando Angular 2 o TypeScript

Empecé a usar get by ServerVariables["HTTP_CF_IPCOUNTRY"] por servidor backend, pero es demasiado lento, necesito una solución Angular o TypeScript para esto.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si desea tomar la ubicación desde el lado frontal, podemos obtener la ubicación simplemente a través de javascript

 var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; }

Esto le pedirá al usuario del navegador que comparta la ubicación, y listo.

Más detalles .

En Angular 2 Component implementa OnInit, coloque ese código dentro de ngOnInit

 import { Component, OnInit } from '@angular/core'; export class LocationComponent implements OnInit { ngOnInit(){ if(window.navigator.geolocation){ window.navigator.geolocation.getCurrentPosition(this.setPosition.bind(this)); }; } } }
over 4 years ago · Santiago Trujillo Report

0

Solución encontrada usando el ejemplo de Vivek.

 ngOnInit() { if (window.navigator && window.navigator.geolocation) { window.navigator.geolocation.getCurrentPosition( position => { this.geolocationPosition = position, console.log(position) }, error => { switch (error.code) { case 1: console.log('Permission Denied'); break; case 2: console.log('Position Unavailable'); break; case 3: console.log('Timeout'); break; } } ); }; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!