gpt4 book ai didi

android - 从地址在 map 上显示位置

转载 作者:行者123 更新时间:2023-12-05 07:52:49 25 4
gpt4 key购买 nike

我想根据他提交的地址显示用户位置。为此,我正在使用 Geocoder。但是我遇到了以下错误。

10-17 18:21:02.734 1914-1934/com.example.googlemapdemo E/GMPM: getGoogleAppId failed with status: 10
10-17 18:21:02.735 1914-1934/com.example.googlemapdemo E/GMPM: Uploading is not possible. App measurement disabled

我已经按照所有步骤获得了 google api key 。这是我的代码

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}

MainActivity.java

Geocoder geocoder = new Geocoder(getApplicationContext());
String result=null;

try {
List addressList = geocoder.getFromLocationName(address.getText().toString(),1);

if(addressList!=null && addressList.size() > 0) {
Address address = (Address) addressList.get(0);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria,true);

double lat = address.getLatitude();
double longti = address.getLongitude();

Log.e("lat..long","lat...long"+lat+"....."+longti);
Intent intent = new Intent(MainActivity.this, MapsActivity.class);
intent.putExtra("Lat",lat);
intent.putExtra("Long",longti);
startActivity(intent);
}
} catch (IOException e) {
e.printStackTrace();
}

map .xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.googlemapdemo.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

map Activity

package com.example.googlemapdemo;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private double lat, longt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
lat = getIntent().getIntExtra("Lat",0);
longt = getIntent().getIntExtra("Long",0);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

/**
* Manipulates the map once available. This callback is triggered when the map is ready to be
* used. This is where we can add markers or lines, add listeners or move the camera. In this
* case, we just add a marker near Sydney, Australia. If Google Play services is not installed
* on the device, the user will be prompted to install it inside the SupportMapFragment. This
* method will only be triggered once the user has installed Google Play services and returned
* to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(lat,longt);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

我还添加了所有权限和 api key 到 menifest

AndroidMenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapdemo" >

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<permission
android:name="package.name.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<uses-library android:name="com.google.android.maps" />

<uses-permission android:name="package.name.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
</activity>
</application>
</manifest>

最佳答案

您需要在开发者控制台上的 key 下添加包名称和 SHA 证书指纹。你做到了吗?

关于android - 从地址在 map 上显示位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33186916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com