我想在特定地点的Google地图上制作标记,我唯一的信息是 Google商家信息ID 。
根据developers.google.com命令getPlaceById()
可以检索到必要的信息,但这对我来说似乎不起作用。
这是我用来申请地方的代码
private void addMarkerById(String id){
android.util.Log.d("MAP", "Finding place for " + id);
Places.GeoDataApi.getPlaceById(mClient, id) .setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(@NonNull PlaceBuffer places) {
if (places.getStatus().isSuccess() && places.getCount() > 0) {
Place place = places.get(0);
mMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(place.getName().toString()));
}
places.release();
}
});
}
地图本身工作正常,手动添加LatLng
也有效。
问题可能在于onResult
,但似乎根本没有运行。
日志
05-17 19:51:52.940 2358-2358/? I/art: Not late-enabling -Xcheck:jni (already on)
05-17 19:51:52.940 2358-2358/? W/art: Unexpected CPU variant for X86 using defaults: x86
05-17 19:51:53.404 2358-2358/be.gillescoeman.scubajournal W/System: ClassLoader referenced unknown path: /data/app/be.gillescoeman.scubajournal-1/lib/x86
05-17 19:51:53.430 2358-2358/be.gillescoeman.scubajournal I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
05-17 19:51:53.431 2358-2358/be.gillescoeman.scubajournal I/InstantRun: starting instant run server: is main process
05-17 19:51:53.556 2358-2358/be.gillescoeman.scubajournal I/zzai: Making Creator dynamically
05-17 19:51:53.559 2358-2358/be.gillescoeman.scubajournal W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
05-17 19:51:53.560 2358-2358/be.gillescoeman.scubajournal D/ApplicationLoaders: ignored Vulkan layer search path /system/priv-app/PrebuiltGmsCore/lib/x86:/system/fake-libs:/system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/system/lib:/vendor/lib for namespace 0xb3ace090
05-17 19:51:53.769 2358-2358/be.gillescoeman.scubajournal W/System: ClassLoader referenced unknown path:
05-17 19:51:53.770 2358-2358/be.gillescoeman.scubajournal W/System: ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86
05-17 19:51:53.770 2358-2358/be.gillescoeman.scubajournal D/ApplicationLoaders: ignored Vulkan layer search path /system/priv-app/PrebuiltGmsCore/lib/x86:/system/fake-libs:/system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/system/lib:/vendor/lib for namespace 0xb3ace0d0
05-17 19:51:53.872 2358-2358/be.gillescoeman.scubajournal W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000002/n/x86
05-17 19:51:54.008 2358-2358/be.gillescoeman.scubajournal I/Google Maps Android API: Google Play services client version: 10240000
05-17 19:51:54.068 2358-2358/be.gillescoeman.scubajournal I/Google Maps Android API: Google Play services package version: 10298470
05-17 19:51:54.290 2358-2428/be.gillescoeman.scubajournal D/NetworkSecurityConfig: No Network Security Config specified, using platform default
05-17 19:51:54.437 2358-2358/be.gillescoeman.scubajournal D/MAP: Locations Executed
05-17 19:51:54.485 2358-2358/be.gillescoeman.scubajournal D/MAP: Finding place for ChIJ5zmn4oo4w0cRUGpTw9AkU0A
[ 05-17 19:51:54.512 2358: 2469 D/ ]
HostConnection::get() New Host Connection established 0xa41c5580, tid 2469
05-17 19:51:54.514 2358-2469/be.gillescoeman.scubajournal I/OpenGLRenderer: Initialized EGL, version 1.4
05-17 19:51:54.514 2358-2469/be.gillescoeman.scubajournal D/OpenGLRenderer: Swap behavior 1
05-17 19:51:54.514 2358-2469/be.gillescoeman.scubajournal W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-17 19:51:54.514 2358-2469/be.gillescoeman.scubajournal D/OpenGLRenderer: Swap behavior 0
05-17 19:51:55.077 2358-2365/be.gillescoeman.scubajournal W/art: Suspending all threads took: 21.665ms
05-17 19:51:56.408 2358-2462/be.gillescoeman.scubajournal W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
05-17 19:51:56.416 2358-2462/be.gillescoeman.scubajournal I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2
05-17 19:51:56.416 2358-2462/be.gillescoeman.scubajournal I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2
答案 0 :(得分:0)
如果onResult
为假,则getStatus().isSuccess()
无效。尝试记录状态,可能会出错。
答案 1 :(得分:0)
我没有设法解决这个问题。
我创建了一个新的数据库表,它存储了该地点所需的所有信息。这允许我在应用中输入新地点时仅使用Places API。添加地点后,我不再需要getPlaceById()
不是解决方案,但它确实使我能够继续开发。