Coding ionic framework 2.
I have a locationtracker, that is giving me the exact latitude and longitude of a person.
I want to have ONLY the string printed from the storeArray, and not the number from the equation.
How is it possible, to ignore the number, from the variable, and only print the store-name out?
this.storeArray = [distValby, distKbhK, distRoskilde];
this.storeArray.sort();
Sorted by lowest number by default.
Fairly new to ionic 2 and typescript in all.
Thanks!
import { StoreLocation } from '../../providers/store-location';
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LocationTracker } from '../../providers/location-tracker';
@Component({
selector: 'page-location',
templateUrl: 'location.html'
})
export class LocationPage implements OnInit{
public usrStoreLat: any;
public usrStoreLong: any;
public usrDistance: any;
public storeArray: Array<any> = [];
public roskilde: StoreLocation = new StoreLocation("Bagel Roskilde", "Trekroner st. 4", 55.650107, 12.131997, null);
public valby: StoreLocation = new StoreLocation("Bagel Valby", "Valby Langgade 12", 55.668071, 12.497865, null);
public kbhK: StoreLocation = new StoreLocation("Indre København", "Axeltorv 5, 1609 København V", 55.6887527, 12.5404156, null);
constructor(public navCtrl: NavController, public locationTracker: LocationTracker) {
}
// START GEO TRACKING FOR NUVÆRENDE POSITION
ngOnInit(){
this.start();
}
public start(){
this.locationTracker.startTracking();
this.usrStoreLat = this.locationTracker.lat;
this.usrStoreLong = this.locationTracker.lng;
if(this.locationTracker.lat != null){
console.log('Tracker nu!');
console.log('person lokation lat:' + this.usrStoreLat);
console.log('person lokation long:' + this.usrStoreLong);
this.calculateDist();
}
}
public calculateDist (){
var distRoskilde = ((this.usrStoreLat-this.roskilde.lat)+(this.usrStoreLong-this.roskilde.long)) + this.roskilde.name;
var distValby = ((this.usrStoreLat-this.valby.lat)+(this.usrStoreLong-this.valby.long)) + this.valby.name;
var distKbhK = ((this.usrStoreLat-this.kbhK.lat)+(this.usrStoreLong-this.kbhK.long)) + this.kbhK.name;
this.storeArray = [distValby, distKbhK, distRoskilde];
this.storeArray.sort();
console.log('se:' + typeof(this.storeArray[0]) + this.storeArray[0].toString());
// console.log('store arrayet:' + this.storeArray[0]);
}
stop(){
this.locationTracker.stopTracking();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<ion-header>
<ion-navbar>
<ion-title>
Location Tracker
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<h4>Current Latitude: {{locationTracker.lat}}</h4>
<h4>Current Longitude: {{locationTracker.lng}}</h4>
<p> Tætteste butik: {{this.storeArray[0]}} </p>
<button ion-button full primary (click)="start()">Find nærmeste butik</button>
<button ion-button full primary (click)="stop()">Stop Tracking</button>
</ion-content>
console.log(this.storeArray[0].name);
Is that what you're asking?const distRoskilde = {latitudeDiff: this.usrStoreLat - this.roskilde.lat, longitudeDiff: this.usrStoreLong - this.roskilde.long, name: this.roskilde.name};