-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
160 lines (111 loc) · 4.47 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
BING MAPS SDK FOR PHP README
=======================
Welcome! This is the Bing Maps SDK for PHP, a library that allows you to
use Bing's APIs to display and interact with Bing Maps in your own web application.
A complete class hierarchy and reference is available in the docs directory
in HTML format.
Directory Structure
===================
The following directories are included in the library:
- lib
Contains the actual source for the SDK
- docs
Contains the autogenerated HTML reference for the SDK's classes
- tests
Contains the unit tests for the SDK
Class Inclusion
===============
In order to use the SDK in your project, you need to copy the lib folder under your web project
and include the following files in your project files:
- lib/Msft/Bing/Exception.php
- lib/Msft/Bing/Map/Map.php
- lib/Msft/Bing/MySQLPersistenceHandler.php
For example, if you web project is called 'bingsdktest', your folder structure should be
bingsdktest
|- test.php
|- lib
|- Msft
|- Bing
|- Exception.php
|- IPersistenceHandler.php
|- MySQLPersistenceHandler.php
|- js
|- addJsFiles.js
|- jquery-1.2.6.js
|- maps.js
|- Map
|- GetResults.php
|- Map.php
Usage
=====
Code Example 1
==============
// File: test.php
<?php
$bingObj = new Msft_Bing_Map('myMap', $myBingMapID);
?>
<html>
<body>
<input type="button" value="Display Map" onclick="<?php $bingObj->displayMap();?>"/>
<div id="myMap"/>
</body>
</html>
The Bing Maps SDK for PHP is designed to give PHP developers an object-oriented
interface to access the Bing Maps API.
The heart of the SDK is the Msft_Bing_Map class. It supports many
methods for interacting with the Bing Maps API.
The API docs give complete details on the methods and parameters.
As you can see from the example above, using the SDK is as simple as
defining a <div> element in your web application, instantiating the class
and calling the displayMap() method. This method in turn will interact with the
Bing Maps web service using Javascript and displays a live map inside the given <div> element.
The second parameter passed into the constructor is your Bing Maps Key.
Each application with which you use the SDK will need its own key. You can obtain
a Bing Maps Key from Microsoft by going to the web page https://www.bingmapsportal.com/
Once you have it, store it in your configuration file somewhere and use it
every time you connect to the Bing Maps API.
Code Example 2
==============
// File: test.php
<?php
$bingObj = new Msft_Bing_Map('myMap', $myBingMapID);
$props = new Msft_Bing_MapProperties('600','500','7');
$props->setDefaultLocation('Bangalore,India');
$bingObj->setProperties($props);
?>
<html>
<body>
<input type="button" value="Display Map"
onclick="<?php $bingObj->displayMap(); $bingObj->addPushpinAddress('Bangalore,India');?>"/>
<div id="myMap"/>
</body>
</html>
Code Example 2 demonstrates the use of addPushpinAddress() method to display a pushpin on the map.
Code Example 3
==============
// File: test.php
<?php
$bingObj = new Msft_Bing_Map('myMap', $myBingMapID);
$props = new Msft_Bing_MapProperties('600','500','7');
$props->setDefaultLocation('Bangalore,India');
$bingObj->setProperties($props);
$handler = new Msft_Bing_MySQLPersistenceHandler($dbhost, $dbname, $dbuser, $dbpassword);
$bingObj->registerPersistenceHandler($handler);
$pin = new Msft_Bing_Pushpin(1, 'FirstPin', 'My Home', 'Bangalore,India');
?>
<html>
<body>
<input type="button" value="Display Map"
onclick="<?php $bingObj->displayMap(); $bingObj->addPushpinPushpin($pin); $bingObj->savePushpins();?>"/>
<div id="myMap" style="position:relative"/>
</body>
</html>
Code Example 3 demonstrates the use of savePushpins() method to save pushpin details in a database.
To save pushpin details and map properties into a database, users have to register a
persistence handler using registerPersistenceHandler() method.
The persistence handler should implement the interface Msft_Bing_IPersistenceHandler.
The SDK includes a default persistence handler which uses MySQL as the backend database.
License
=======
This library is released free of charge under the terms of the GNU General Public License v2.
A copy of the license is available in the LICENSE file, included in the distribution.