简体   繁体   English

如何在谷歌地图的屏幕中心设置标记

[英]How to set marker on center of the screen in google map

I'm making an transport's app like uber or lyft with javascript. 我正在使用javascript制作uber或lyft等交通工具的应用程序。 I need to get the map location through the center of the screen, where I have a marker at y = 0 and x = 0. 我需要通过屏幕中心获取地图位置,我在y = 0和x = 0处有一个标记。

Like this image: 喜欢这张图片:

lyft应用

With the finger moves the screen and automatically registers the new position, since the marker is always in the center of the screen. 用手指移动屏幕并自动注册新位置,因为标记始终位于屏幕中央。

Anyone who can help me? 谁能帮助我? Thank you very much 非常感谢你

What you need is listen to the center_changed event of the map and take the lat-long of the center.As you said the marker will always be at the center of the map. 您需要的是聆听地图的center_changed事件,并获取中心的经纬度。正如您所说的,标记始终位于地图的中心。

this.map = new google.maps.Map(this.mapElement.nativeElement);
_this = this; 
google.maps.event.addListener(this.map, 'center_changed', function () {
      _this.latLngObj = _this.map.getCenter();
     console.log('lat long object '+ _this.latLngObj);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM