te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - how to use fromPointToLatLng on google maps v3 - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to use fromPointToLatLng on google maps v3 - Stack Overflow

programmeradmin3浏览0评论

This is my code:

var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map,'projection_changed', function () {
    var proj = map.getProjection();
    ltBound = proj.fromPointToLatLng(new google.maps.Point(0,100))
    rbBound = proj.fromPointToLatLng(new google.maps.Point(100,200))
    console.log(ltBound,rbBound)
});

I want to make a node on Google Maps, but I can't use the fromPointToLatLng on right way. What can I do?

This is my code:

var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map,'projection_changed', function () {
    var proj = map.getProjection();
    ltBound = proj.fromPointToLatLng(new google.maps.Point(0,100))
    rbBound = proj.fromPointToLatLng(new google.maps.Point(100,200))
    console.log(ltBound,rbBound)
});

I want to make a node on Google Maps, but I can't use the fromPointToLatLng on right way. What can I do?

Share Improve this question edited Oct 16, 2013 at 14:36 Martin Geisler 73.8k25 gold badges174 silver badges230 bronze badges asked Sep 16, 2010 at 1:27 zjm1126zjm1126 35.7k53 gold badges125 silver badges167 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

Here's how I use the method fromPointToLatLng(). You first need to find the Lat / Lng of the top left point on the map then calculate an offset from there.

var pixelToLatlng = function(xcoor, ycoor) {
  var ne = map.getBounds().getNorthEast();
  var sw = map.getBounds().getSouthWest();
  var projection = map.getProjection();
  var topRight = projection.fromLatLngToPoint(ne);
  var bottomLeft = projection.fromLatLngToPoint(sw);
  var scale = 1 << map.getZoom();
  var newLatlng = projection.fromPointToLatLng(new google.maps.Point(xcoor / scale + bottomLeft.x, ycoor / scale + topRight.y));
  return newLatlng;
};

Try out the fiddle here: http://jsfiddle/mhaq865o/5/

You can either use the fromPointToLatLng() method or OverlayView method as described here http://magicalrosebud./how-to-use-googlemaps-api-frompointtolatlng/

The fromPointToLatLng and fromLatLngToPoint methods in Projection translate between points in a 256x256 coordinate system and real world coordinates.

The entire Google Map is 256x256 pixels when you are at zoom level 0. Try zooming out and outputting the point you get when you click around the map:

google.maps.event.addListener(map, 'click', function(event) {
    var proj = map.getProjection();
    console.log('latLng: ' + event.latLng);
    console.log('Point:  ' + proj.fromLatLngToPoint(event.latLng));
});

I think you only need to know/use this if you want to pute a zoom level or do something similar where you need to know the relationship between real world coordinates and on-screen pixels.

You ask about adding a "node" to the map. If you're thinking of what the documentation calls "markers", then see their section on markers.

发布评论

评论列表(0)

  1. 暂无评论