google map 点与点画线
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Map</title> <style type="text/css">
body {
margin: 0;
padding: 0;
} img {
border-radius: 5px;
} .image_border {
border: 2px solid red !important;
width: 46px !important;
height: 54px !important;
} #content {
width: 800px;
height: 1000px;
border: 1px solid navy;
margin: auto;
padding: auto;
}
</style> <script src="http://localhost/static/js/jquery-2.1.0.min.js" type="text/javascript" ></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
</head> <body> <div id='content'>
<div id="map_canvas" style="width:100%; height:100%"></div>
</div> </body>
</html> <script type="text/javascript"> // 地图描点列表对象
var location_list = [
{'id':'1', 'name':'user01', 'image_url':'./image/photo_1.png', 'longitude':'-34.397', 'latitude':'150.644'},
{'id':'2', 'name':'user02', 'image_url':'./image/photo_2.png', 'longitude':'-33.397', 'latitude':'151.644'},
{'id':'3', 'name':'user03', 'image_url':'./image/photo_3.png', 'longitude':'-35.397', 'latitude':'150.644'}
]; /**
*
* 初始化
*
*/
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644), // 显示地图的中心点位置
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}; var map = new google.maps.Map(
document.getElementById("map_canvas"),
mapOptions
); google_maps_add_location(map);
} /**
*
* 添加需要在地图上显示的点
*
*/
function google_maps_add_location(map) {
for (var i = 0; i < location_list.length; i++) {
add_location(map, location_list[i]);
add_polyline(map, location_list[0], location_list[i]);
};
} /**
*
* 添加单个地图描点
* 并为此描点添加click事件
*
*/
function add_location(map, location) { var image = location.image_url;
var myLatLng = new google.maps.LatLng(location.longitude, location.latitude);
var beachMarker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: location.name,
zIndex: 0,
// 单独的层,可以为这个层添加CSS效果等,如果为true,此层和地图层将被视为一体
// 比如将图片变成圆角图片 border-radius: 5px;
optimized:false
}); google.maps.event.addListener(beachMarker, 'click', function(){
alert('id:' + location.id + ', name:' + location.name);
$('#map_canvas img').removeClass('image_border');
$('#map_canvas img[src="./image/photo_' + location.id + '.png"]').addClass('image_border');
});
} /**
*
* 为用户画关系线
*
*/
function add_polyline(map, current_location, object_location) {
var flightPlanCoordinates = [
new google.maps.LatLng(current_location.longitude, current_location.latitude),
new google.maps.LatLng(object_location.longitude, object_location.latitude)
]; var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
}); flightPath.setMap(map);
} // 初始监听事件
google.maps.event.addDomListener(window, 'load', initialize);
</script>
google map 点与点画线的更多相关文章
- Google Map API V3开发(1)
Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...
- Google Map API V3开发(3)
Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...
- Google Map API 使用总结
Google Map API (一):显示一个最基本的地图 1 实现一个地图:<head>中引用: <script type="text/javascript" ...
- Android中Google地图路径导航,使用mapfragment地图上画出线路(google map api v2)详解
在这篇里我们只聊怎么在android中google map api v2地图上画出路径导航,用mapfragment而不是mapview,至于怎么去申请key,manifest.xml中加入的权限,系 ...
- Google Map JavaScript API V3 实例大全
Google Map JavaScript API V3 实例大全 基础知识 简单的例子 地理位置 语言 位置 坐标 简单的投影 事件 简单事件 关闭事件 多次添加事件 事件属性 控制 php禁用ui ...
- Google Map API v2 步步为营 (二)----- Location
接上篇. 改造一下MapsActivity: public class MapsActivity extends Activity implements LocationListener, InfoW ...
- 爬坑之路---Google map
google.maps.event.adddDomListen(window, 'load', callback);当文档流中所有的dom加载完成后,执行回调函数,可以不用在script中使用defe ...
- 房产地图google map的初步应用点滴.4)(转)
房产地图google map的初步应用点滴.1) 房产地图google map的初步应用点滴.2) 房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) ...
- Google Map API 应用实例说明
目录 Google Map API 1基础知识 1.1 Google 地图 API 概念 1.2 Google 地图的"Hello, World" 1.2.1 加载 Google ...
随机推荐
- 微信朋友圈分享页面(JS-SDK 1.0)
微信更新sdk后大量分享朋友圈代码失效,标题 缩略图 描述无法自定义 新版SDK分享文章步骤 1.绑定域名 (方法参考 http://mp.weixin.qq.com/wiki/7/aaa137b55 ...
- iOS UIButton加在window上点击无效果问题
UIButton加在window上,点击没有效果,找了很久,原来是没有加上这名:[self.window makeKeyAndVisible]; self.window = [[UIWindow al ...
- 写了个SharedPreferences的工具类(带加密)
/* * Copyright (C) 2014 Jason Fang ( ijasonfang@gmail.com ) * * Licensed under the Apache License, V ...
- QFtp类参考
QFtp是一个用来实现FTP协议的类. 详情请见…… #include <qftp.h> 继承了QNetworkProtocol. 所有成员函数的列表. 公有成员 QFtp () virt ...
- Helpers\Database
Helpers\Database The database class is used to connect to a MySQL database using the connection deta ...
- 琐碎-将hadoop源码作为工程导入eclipse
之前写过如何用eclipse看hadoop源码,虽然非官方版的,但是可以达到目的,最重要是简单方便快速 官方版(hadoop2.2.0)的也有: 源码目录为: 和之前的源码目录有很大的不同 编译的时候 ...
- LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。
var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...
- LeetCode 283
Move Zeros Given an array nums, write a function to move all 0's to the end of it while maintaining ...
- LeetCode 203
Remove Linked List Elements Remove all elements from a linked list of integers that have value val. ...
- 用bash命令得到Windows一个目录下的所有文件并且把结果输入到一个文件
方式一: 只用如下一条语句就可以了: tree/f>index.txt 放入一个文件中命名为"****.bat" 双击就会在该目录下生成一个index.txt文件,在这个文件 ...