Hello I am trying to get the latitude and longitude in angular and save it in firebase it gives me this error
My code is:
import { Component, OnInit } from '@angular/core'; import { PlacesService } from '../services/places.service';
@Component({ selector: 'app-create', templateUrl: './create.component.html', styleUrls: ['./create.component.css'] }) export class CreateComponent { place: any = {}; constructor(private placesService: PlacesService) { } savePlace() {
var direccion = this.lugar.calle+','+ this.lugar.ciudad+','+this.lugar.pais;
this.lugaresService.obtenerGeoData(direccion)
.subscribe((result) => {
this.lugar.lat = result[0].geometry.location.lat;
this.lugar.lng = result[0].geometry.location.lng;
this.lugar.id = Date.now();
this.lugaresService.guardarLugar(this.lugar);
alert('Indicio guardado con exito');
this.lugar = {};
});
var direccion = this.lugar.calle+','+ this.lugar.ciudad+','+this.lugar.pais;
this.lugaresService.obtenerGeoData(direccion)
.subscribe((result) =>{
this.lugar.lat = this.lugar.lat = result[0].geometry.location.lat;;
this.lugar.lng = this.lugar.lng = result[0].geometry.location.lng;
this.lugar.id = Date.now();
this.lugaresService.guardarLugar(this.lugar);
alert('Indicio guardado con exito');
this.lugar = {};
});
}
}
/*
and so I call the service
public obtenerGeoData(direccion) {
return this.http.get('http://maps.google.com/maps/api/geocode/json?address=' + direccion + '&key=<tu api key>' );
}
I didn't get anything in the result since the google maps api had it in http and I changed it to https so I concatenated my api key like this:
'https://maps.google.com/maps/api/geocode/json?address=' + direccion + '&key=<Aqui tu apiKey>'
then I put a debugger to see what the result contained, so I saw that I already got the geolocation and clicked Instead of the console navigate until you get the latitude and longitude ending like this: