Closed qianzhiheilv closed 7 years ago
I get lat&lng from gprs,but it need to be transfer to lat&lng in map,I find a way to chang it
export function latLng2Point(latLng, map) {
var topRight = map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast()); var bottomLeft = map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest()); var scale = Math.pow(2, map.getZoom()); var worldPoint = map.getProjection().fromLatLngToPoint(latLng); return new google.maps.Point((worldPoint.x - bottomLeft.x) * scale, (worldPoint.y - topRight.y) * scale); } export function point2LatLng(point, map) { var topRight = map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast()); var bottomLeft = map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest()); var scale = Math.pow(2, map.getZoom()); var worldPoint = new google.maps.Point(point.x / scale + bottomLeft.x, point.y / scale + topRight.y); return map.getProjection().fromPointToLatLng(worldPoint); }
I need map object,I use refs to get mapObject,but it is not right.
<gmap-map :center="center" :zoom="15" style="position: inherit; left: 10%; right: 10%; height:300px;width:300px;" ref="googleMap"> <gmap-marker :key="i" v-for="(m,i) in markers" :position="m.position" :clickable="false" :draggable="false"></gmap-marker> </gmap-map> var point = {x:31.582610,y:118.445242}; console.log(this.$point2LatLng(point,this.$refs.googleMap.$mapObject));
How can l get mapObject of google?Thank you very much.
I get lat&lng from gprs,but it need to be transfer to lat&lng in map,I find a way to chang it
export function latLng2Point(latLng, map) {
I need map object,I use refs to get mapObject,but it is not right.
How can l get mapObject of google?Thank you very much.