Commit c42ab802 authored by Maxim Safronov's avatar Maxim Safronov
Browse files

Первая попытка внедрения Google-сервисов для работы с геолокацией, пока не успешно

parent 9b8c2476
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/build/classes" />
  </component>
  <component name="ProjectType">
+3 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ android {
        }
    }
    compileOptions {
        targetCompatibility = 1.8
        sourceCompatibility = 1.8
        targetCompatibility = 1.7
        sourceCompatibility = 1.7
    }
}

@@ -44,4 +44,5 @@ dependencies {
    implementation 'com.yandex.android:places:3.4.0'
    implementation 'com.yandex.android:search:3.4.0'
    implementation 'com.yandex.android:transport:3.4.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
}
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pw.cyberbrain.penzatransport">

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
+25 −1
Original line number Diff line number Diff line
package pw.cyberbrain.penzatransport;

import androidx.appcompat.app.AppCompatActivity;

import android.location.Location;
import android.os.Bundle;

import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.yandex.mapkit.Animation;
import com.yandex.mapkit.MapKitFactory;
import com.yandex.mapkit.geometry.Point;
@@ -9,9 +14,14 @@ import com.yandex.mapkit.map.CameraPosition;

import com.yandex.mapkit.mapview.MapView;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;

public class MainActivity extends AppCompatActivity {

    private MapView mapview;
    private FusedLocationProviderClient fusedLocationClient;
    private float user_alt, user_long;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -20,11 +30,25 @@ public class MainActivity extends AppCompatActivity {
        MapKitFactory.setApiKey("6385dca0-e464-4359-b337-e62a44ebfa70");
        MapKitFactory.initialize(this);

        fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
        fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {

            @Override
            public void onSuccess(Location location) {
            // Got last known location. In some rare situations this can be null.
                if (location != null) {
                    // Logic to handle location object
                    user_alt = (float)location.getAltitude();
                    user_long = (float)location.getLongitude();
                    }
                }
            });

        // Укажите имя activity вместо map.
        setContentView(R.layout.activity_main);
        mapview = findViewById(R.id.mapview);
        mapview.getMap().move(
                new CameraPosition(new Point(55.751574, 37.573856), 5.0f, 0.0f, 0.0f),
                new CameraPosition(new Point(user_alt, user_long), 5.0f, 0.0f, 0.0f),
                new Animation(Animation.Type.SMOOTH, 0),
                null);
    }