├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── noman │ │ └── places │ │ └── ApplicationTest.java │ ├── debug │ └── res │ │ └── values │ │ └── google_maps_api.xml │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── noman │ │ │ └── places │ │ │ └── example │ │ │ └── MapsActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── activity_maps.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── release │ └── res │ │ └── values │ │ └── google_maps_api.xml │ └── test │ └── java │ └── noman │ └── places │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── placesAPI ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── noman │ │ └── googleplaces │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── noman │ │ │ └── googleplaces │ │ │ ├── AbstractPlaces.java │ │ │ ├── NRPlaces.java │ │ │ ├── Parser.java │ │ │ ├── Place.java │ │ │ ├── PlaceType.java │ │ │ ├── PlacesException.java │ │ │ ├── PlacesListener.java │ │ │ └── PlacesParser.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── noman │ └── googleplaces │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | 28 | # Android Studio 29 | *.iml 30 | .idea 31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 32 | .gradle 33 | build/ 34 | 35 | #FacebookSDK 36 | /FacebookSDK/build/ 37 | /FacebookSDK/FacebookSDK.iml 38 | /facebook/build/ 39 | /facebook/facebook.iml 40 | 41 | #simple-crop-image-lib 42 | /simple-crop-image-lib/build/ 43 | /simple-crop-image-lib/simple-crop-image-lib.iml 44 | 45 | #NDK 46 | obj/ 47 | 48 | 49 | #Except for these files/folders 50 | !.gitignore 51 | !*/app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android-Google-Places-API 2 | ========================= 3 | 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android--Google--Places--API-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/4463) 5 | 6 | 7 | This project allows you get places in a given radius and other Places API parameter using Google Places API. 8 | 9 | 10 | 11 | 12 | Sample 13 | ------------ 14 | 15 | The sample makes use of the Google Places API for Android in order to provide a real life example of how the library can be used. [Dropbox Link](https://www.dropbox.com/s/47eq14a5tj2vqmq/Places-Demo.apk?dl=0) 16 | 17 | Download 18 | -------- 19 | 20 | 21 | Grab via Maven: 22 | ```xml 23 | 24 | noman.placesapi 25 | placesAPI 26 | 1.0.0 27 | 28 | ``` 29 | or Gradle: 30 | ```groovy 31 | compile 'noman.placesapi:placesAPI:1.1.3' 32 | ``` 33 | 34 | Usage 35 | ----- 36 | 37 | To get places within a radius, pass the central point , API key and just execute the NRPlaces Object. 38 | 39 | 40 | *You can execute the task in this manner. ( See the example for more details on the exact implementation) 41 | 42 | 43 | 44 | ``` java 45 | 46 | new NRPlaces.Builder() 47 | .listener(this) 48 | .key("KEY") 49 | .latlng(33.721328, 73.057838) 50 | .radius(500) 51 | .type(PlaceType.GYM) 52 | .build() 53 | .execute(); 54 | 55 | ``` 56 | Callbacks 57 | 58 | ``` java 59 | 60 | void onPlacesFailure(PlacesException e); 61 | 62 | void onPlacesStart(); 63 | 64 | void onPlacesSuccess(List places); 65 | 66 | void onPlacesFinished(); 67 | ``` 68 | 69 | License 70 | -------- 71 | 72 | Copyright 2016 Noman Rafique 73 | 74 | Licensed under the Apache License, Version 2.0 (the "License"); 75 | you may not use this file except in compliance with the License. 76 | You may obtain a copy of the License at 77 | 78 | http://www.apache.org/licenses/LICENSE-2.0 79 | 80 | Unless required by applicable law or agreed to in writing, software 81 | distributed under the License is distributed on an "AS IS" BASIS, 82 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 83 | See the License for the specific language governing permissions and 84 | limitations under the License. 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "noman.places.example" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | // compile 'noman.placesapi:placesAPI:1.1.2' 26 | compile project(':placesAPI') 27 | compile 'com.android.support:appcompat-v7:23.4.0' 28 | compile 'com.google.android.gms:play-services:9.0.2' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\nor\AppData\Local\Android\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/noman/places/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package noman.places; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/debug/res/values/google_maps_api.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AIzaSyBCXlI-L8SupDygQOmckjv3xa7dP1rAoKk 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/noman/places/example/MapsActivity.java: -------------------------------------------------------------------------------- 1 | package noman.places.example; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.util.Log; 6 | 7 | import com.google.android.gms.maps.CameraUpdateFactory; 8 | import com.google.android.gms.maps.GoogleMap; 9 | import com.google.android.gms.maps.OnMapReadyCallback; 10 | import com.google.android.gms.maps.SupportMapFragment; 11 | import com.google.android.gms.maps.model.BitmapDescriptorFactory; 12 | import com.google.android.gms.maps.model.LatLng; 13 | import com.google.android.gms.maps.model.MarkerOptions; 14 | 15 | import java.util.List; 16 | 17 | import noman.googleplaces.NRPlaces; 18 | import noman.googleplaces.Place; 19 | import noman.googleplaces.PlacesException; 20 | import noman.googleplaces.PlacesListener; 21 | import noman.places.R; 22 | 23 | public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, PlacesListener { 24 | 25 | private GoogleMap mMap; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_maps); 31 | // Obtain the SupportMapFragment and get notified when the map is ready to be used. 32 | SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 33 | .findFragmentById(R.id.map); 34 | mapFragment.getMapAsync(this); 35 | 36 | } 37 | 38 | 39 | @Override 40 | public void onMapReady(GoogleMap googleMap) { 41 | mMap = googleMap; 42 | 43 | // Add a marker in Sydney and move the camera 44 | LatLng islamabad = new LatLng(33.721328, 73.057838); 45 | mMap.addMarker(new MarkerOptions().position(islamabad).title("Center Point") 46 | .icon((BitmapDescriptorFactory 47 | .defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)))); 48 | mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(islamabad, 15)); 49 | 50 | new NRPlaces.Builder() 51 | .listener(this) 52 | .key("KEY") 53 | .latlng(33.721328, 73.057838) 54 | .radius(1500) 55 | .build() 56 | .execute(); 57 | } 58 | 59 | @Override 60 | public void onPlacesFailure(PlacesException e) { 61 | Log.i("PlacesAPI", "onPlacesFailure()"); 62 | } 63 | 64 | @Override 65 | public void onPlacesStart() { 66 | Log.i("PlacesAPI", "onPlacesStart()"); 67 | } 68 | 69 | @Override 70 | public void onPlacesSuccess(final List places) { 71 | Log.i("PlacesAPI", "onPlacesSuccess()"); 72 | runOnUiThread(new Runnable() { 73 | @Override 74 | public void run() { 75 | for (Place place : places) { 76 | 77 | LatLng latLng = new LatLng(place.getLatitude(), place.getLongitude()); 78 | mMap.addMarker(new MarkerOptions().position(latLng) 79 | .title(place.getName()).snippet(place.getVicinity())); 80 | 81 | } 82 | 83 | } 84 | }); 85 | 86 | 87 | } 88 | 89 | @Override 90 | public void onPlacesFinished() { 91 | Log.i("PlacesAPI", "onPlacesFinished()"); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_maps.xml: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Google-Places 3 | Map 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/release/res/values/google_maps_api.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | YOUR_KEY_HERE 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/test/java/noman/places/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package noman.places; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' 10 | classpath "com.github.dcendents:android-maven-gradle-plugin:1.4.1" 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven { 20 | url "http://dl.bintray.com/nomanrafique/maven" 21 | } 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomanr/Android-Google-Places-API/911d72080272d96cd693e806d785f968ce3d97ca/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 06 11:19:44 PKT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /placesAPI/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /placesAPI/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.jfrog.bintray' 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | 5 | android { 6 | compileSdkVersion 23 7 | buildToolsVersion "23.0.3" 8 | 9 | defaultConfig { 10 | minSdkVersion 15 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | 16 | } 17 | group = 'noman.placesapi' 18 | version = '1.1.3' 19 | 20 | task generateSourcesJar(type: Jar) { 21 | from android.sourceSets.main.java.srcDirs 22 | classifier 'sources' 23 | } 24 | 25 | task generateJavaDocs(type: Javadoc) { 26 | source = android.sourceSets.main.java.srcDirs 27 | classpath += project.files(android.getBootClasspath() 28 | .join(File.pathSeparator)) 29 | } 30 | 31 | task generateJavaDocsJar(type: Jar) { 32 | from generateJavaDocs.destinationDir 33 | classifier 'javadoc' 34 | } 35 | generateJavaDocsJar.dependsOn generateJavaDocs 36 | 37 | bintray { 38 | user = 'nomanrafique' 39 | key = 'KEY' 40 | pkg { 41 | repo = 'maven' 42 | name = 'placesapi' 43 | 44 | version { 45 | name = '1.1.3' 46 | desc = 'GooglePlacesAPI' 47 | released = new Date() 48 | vcsTag = '1.1.3' 49 | } 50 | 51 | licenses = ['Apache-2.0'] 52 | vcsUrl = 'https://github.com/nomanr/Android-Google-Places-API' 53 | websiteUrl = 'https://github.com/nomanr/Android-Google-Places-API' 54 | } 55 | configurations = ['archives'] 56 | } 57 | 58 | artifacts { 59 | archives generateJavaDocsJar 60 | archives generateSourcesJar 61 | } 62 | 63 | -------------------------------------------------------------------------------- /placesAPI/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\nor\AppData\Local\Android\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /placesAPI/src/androidTest/java/noman/googleplaces/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /placesAPI/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/AbstractPlaces.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.os.AsyncTask; 4 | import android.util.Log; 5 | import android.util.Pair; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by Noman on 8/25/2016. 12 | */ 13 | public abstract class AbstractPlaces extends AsyncTask> { 14 | protected final String PARAM_KEY = "key="; 15 | protected final String PARAM_LOCATION = "location="; 16 | protected final String PARAM_RADIUS = "radius="; 17 | protected final String PARAM_RANK_BY = "rankby="; 18 | protected final String PARAM_KEYWORD = "keyword="; 19 | protected final String PARAM_LANGUAGE = "language="; 20 | protected final String PARAM_MINPRICE = "minprice="; 21 | protected final String PARAM_MAXPRICE = "maxprice="; 22 | protected final String PARAM_NAME = "name="; 23 | protected final String PARAM_TYPE = "type="; 24 | protected final String PARAM_PAGETOKEN = "pagetoken="; 25 | protected String PLACES_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"; 26 | /** 27 | * Exception to return in callback 28 | */ 29 | private PlacesException exception; 30 | 31 | /** 32 | * listener callback for sending back response 33 | */ 34 | 35 | private List listeners; 36 | 37 | protected AbstractPlaces(PlacesListener listener) { 38 | this.listeners = new ArrayList<>(); 39 | registerListener(listener); 40 | } 41 | 42 | @Override 43 | protected List doInBackground(Void... params) { 44 | try { 45 | //first 20 records 46 | Pair> pair = 47 | new PlacesParser(constructURL(null)).parseNearbyPlaces(); 48 | dispatchOnSuccess(pair.second); 49 | //check for 20-40records 50 | if (pair.first != null) { 51 | Thread.sleep(2000); //http://stackoverflow.com/questions/9783829/issue-with-google-places-api-invalid-request 52 | pair = new PlacesParser(constructURL(pair.first)).parseNearbyPlaces(); 53 | dispatchOnSuccess(pair.second); 54 | 55 | //check for 40-60 records 56 | if (pair.first != null) { 57 | Thread.sleep(2000); 58 | pair = new PlacesParser(constructURL(pair.first)).parseNearbyPlaces(); 59 | dispatchOnSuccess(pair.second); 60 | 61 | } 62 | } 63 | 64 | return pair.second; 65 | } catch (PlacesException e) { 66 | exception = e; 67 | dispatchOnFailure(e); 68 | return null; 69 | } catch (InterruptedException e) { 70 | e.printStackTrace(); 71 | return null; 72 | } 73 | } 74 | 75 | @Override 76 | protected void onPreExecute() { 77 | dispatchOnStart(); 78 | } 79 | 80 | @Override 81 | protected void onPostExecute(List places) { 82 | if (places == null) { 83 | dispatchOnFailure(exception); 84 | } else { 85 | dispatchOnFinished(); 86 | } 87 | 88 | } 89 | 90 | 91 | public void registerListener(PlacesListener mListener) { 92 | if (mListener != null) { 93 | listeners.add(mListener); 94 | } 95 | } 96 | 97 | protected void dispatchOnStart() { 98 | for (PlacesListener mListener : listeners) { 99 | mListener.onPlacesStart(); 100 | } 101 | } 102 | 103 | protected void dispatchOnFailure(PlacesException exception) { 104 | Log.e("Places", exception.toString()); 105 | for (PlacesListener mListener : listeners) { 106 | mListener.onPlacesFailure(exception); 107 | 108 | } 109 | } 110 | 111 | protected void dispatchOnSuccess(List places) { 112 | for (PlacesListener mListener : listeners) { 113 | mListener.onPlacesSuccess(places); 114 | } 115 | } 116 | 117 | private void dispatchOnFinished() { 118 | for (PlacesListener mListener : listeners) { 119 | mListener.onPlacesFinished(); 120 | } 121 | } 122 | 123 | protected abstract String constructURL(String nexPageToken); 124 | 125 | 126 | } 127 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/NRPlaces.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.util.Log; 4 | 5 | import java.util.List; 6 | import java.util.Locale; 7 | 8 | /** 9 | * Created by Noman on 8/25/2016. 10 | */ 11 | public class NRPlaces extends AbstractPlaces { 12 | 13 | /** 14 | * Required API key, 15 | * https://developers.google.com/places/web-service/get-api-key 16 | */ 17 | private String key; 18 | /** 19 | * REQUIRED 20 | * location — The latitude/longitude around which to retrieve place information. 21 | * This must be specified as latitude,longitude. 22 | */ 23 | private String location; 24 | /** 25 | * radius — Defines the distance (in meters) within which to return place results. 26 | * The maximum allowed radius is 50 000 meters. 27 | * Note that radius must not be included if rankby=distance 28 | * (described under Optional parameters below) is specified. 29 | */ 30 | private int radius = -1; 31 | 32 | /** 33 | * prominence & distance 34 | * rankby=distance (described under Optional parameters below) is specified, 35 | * then one or more of keyword, name, or type is required. 36 | */ 37 | private String rankby; 38 | /** 39 | * keyword — A term to be matched against all content that Google has indexed for this place, 40 | * including but not limited to name, type, and address, 41 | * as well as customer reviews and other third-party content. 42 | */ 43 | private String keyword; 44 | 45 | /** 46 | * minprice and maxprice (optional) — 47 | * Restricts results to only those places within the specified range. 48 | * Valid values range between 0 (most affordable) to 4 49 | */ 50 | private int minprice = -1; 51 | /** 52 | * minprice and maxprice (optional) — 53 | * Restricts results to only those places within the specified range. 54 | * Valid values range between 0 (most affordable) to 4 55 | */ 56 | private int maxprice = -1; 57 | 58 | /** 59 | * name — One or more terms to be matched against the names of places, 60 | */ 61 | private String[] name; 62 | /** 63 | * opennow — Returns only those places that are 64 | * open for business at the time the query is sent. 65 | */ 66 | private boolean opennow; 67 | /** 68 | * type — Restricts the results to places matching the specified type. 69 | * Only one type may be specified (if more than one type is provided, 70 | * all types following the first entry are ignored). 71 | */ 72 | private String type; 73 | /** 74 | * the language code, indicating in which language the results should be returned, 75 | */ 76 | private String language; 77 | /** 78 | * Country code e.g. US 79 | */ 80 | private String countryCode; 81 | private PlacesListener listener; 82 | 83 | private NRPlaces(Builder builder) { 84 | super(builder.listener); 85 | setKey(builder.key); 86 | if (builder.lat == -1 || builder.lng == -1) { 87 | setLocation(null); 88 | } else { 89 | setLocation(builder.lat + "," + builder.lng); 90 | } 91 | setRadius(builder.radius); 92 | setRankby(builder.rankby); 93 | setKeyword(builder.keyword); 94 | setMinprice(builder.minprice); 95 | setMaxprice(builder.maxprice); 96 | setName(builder.name); 97 | setOpennow(builder.opennow); 98 | setType(builder.type); 99 | setListener(builder.listener); 100 | setLanguage(builder.language); 101 | setCountryCode(builder.countryCode); 102 | } 103 | 104 | public String getCountryCode() { 105 | return countryCode; 106 | } 107 | 108 | public void setCountryCode(String countryCode) { 109 | this.countryCode = countryCode; 110 | } 111 | 112 | public String getLanguage() { 113 | return language; 114 | } 115 | 116 | public void setLanguage(String language) { 117 | this.language = language; 118 | } 119 | 120 | public String getKey() { 121 | return key; 122 | } 123 | 124 | public void setKey(String key) { 125 | this.key = key; 126 | } 127 | 128 | public String getLocation() { 129 | return location; 130 | } 131 | 132 | public void setLocation(String location) { 133 | this.location = location; 134 | } 135 | 136 | public int getRadius() { 137 | return radius; 138 | } 139 | 140 | public void setRadius(int radius) { 141 | this.radius = radius; 142 | } 143 | 144 | public String getRankby() { 145 | return rankby; 146 | } 147 | 148 | public void setRankby(String rankby) { 149 | this.rankby = rankby; 150 | } 151 | 152 | public String getKeyword() { 153 | return keyword; 154 | } 155 | 156 | public void setKeyword(String keyword) { 157 | this.keyword = keyword; 158 | } 159 | 160 | public int getMinprice() { 161 | return minprice; 162 | } 163 | 164 | public void setMinprice(int minprice) { 165 | this.minprice = minprice; 166 | } 167 | 168 | public int getMaxprice() { 169 | return maxprice; 170 | } 171 | 172 | public void setMaxprice(int maxprice) { 173 | this.maxprice = maxprice; 174 | } 175 | 176 | public String[] getName() { 177 | return name; 178 | } 179 | 180 | public void setName(String[] name) { 181 | this.name = name; 182 | } 183 | 184 | public boolean isOpennow() { 185 | return opennow; 186 | } 187 | 188 | public void setOpennow(boolean opennow) { 189 | this.opennow = opennow; 190 | } 191 | 192 | public String getType() { 193 | return type; 194 | } 195 | 196 | public void setType(String type) { 197 | this.type = type; 198 | } 199 | 200 | public PlacesListener getListener() { 201 | return listener; 202 | } 203 | 204 | public void setListener(PlacesListener listener) { 205 | this.listener = listener; 206 | } 207 | 208 | @Override 209 | protected String constructURL(String nexPageToken) { 210 | StringBuilder builder = new StringBuilder(PLACES_URL); 211 | 212 | if (key == null) { 213 | throw new IllegalArgumentException("API key is required"); 214 | } 215 | builder.append(PARAM_KEY).append(key); 216 | if (nexPageToken != null) { 217 | builder.append("&").append(PARAM_PAGETOKEN).append(nexPageToken); 218 | Log.e("Places", builder.toString()); 219 | return builder.toString(); 220 | 221 | } 222 | 223 | if (location == null) { 224 | throw new IllegalArgumentException("Location lat/lng is required"); 225 | } 226 | builder.append("&").append(PARAM_LOCATION).append(location); 227 | 228 | if (radius != -1 && rankby != null) { 229 | throw new IllegalArgumentException("'radius' and 'rankby' cannot work together"); 230 | } else if (radius == -1 && rankby == null) { 231 | throw new IllegalArgumentException("'radius' is required"); 232 | } else if (radius != -1) { 233 | if (radius > 50000) { 234 | throw new IllegalArgumentException("'radius' cannot be > 50000"); 235 | } 236 | builder.append("&").append(PARAM_RADIUS).append(String.valueOf(radius)); 237 | } else { 238 | if (rankby.equals("distance") || rankby.equals("prominence")) { 239 | builder.append("&").append(PARAM_RANK_BY).append(rankby); 240 | } else { 241 | throw new IllegalArgumentException( 242 | "'rankby' can only be 'distance' or 'prominence' "); 243 | } 244 | } 245 | 246 | if (keyword != null) { 247 | builder.append("&").append(PARAM_KEYWORD).append(keyword); 248 | } 249 | 250 | if (language != null) { 251 | Locale locale = new Locale(language); 252 | if (locale.getISO3Language() == null || locale.getISO3Country().isEmpty()) { 253 | if (countryCode != null) { 254 | locale = new Locale(language, countryCode); 255 | } else { 256 | locale = new Locale(language, language); 257 | } 258 | if (locale.getISO3Language() == null || locale.getISO3Country().isEmpty()) { 259 | throw new IllegalArgumentException( 260 | "Invalid language code"); 261 | } 262 | } 263 | builder.append("&").append(PARAM_LANGUAGE).append(language); 264 | } 265 | if (minprice != -1 & maxprice != -1) { 266 | if (minprice > maxprice) { 267 | throw new IllegalArgumentException("'minprice' should be less than 'maxprice'"); 268 | } else if (minprice > 4 || maxprice > 4) { 269 | throw new IllegalArgumentException( 270 | "'minprice' and 'maxprice' should be less equal to 4"); 271 | } else if (minprice < 0 || maxprice < 0) { 272 | throw new IllegalArgumentException( 273 | "'minprice' and 'maxprice' should be greater equal to 0"); 274 | } else { 275 | builder.append("&").append(PARAM_MINPRICE).append(String.valueOf(minprice)); 276 | builder.append("&").append(PARAM_MAXPRICE).append(String.valueOf(maxprice)); 277 | } 278 | } 279 | if (name != null) { 280 | String names = ""; 281 | for (int i = 0; i < name.length; i++) { 282 | if (!names.isEmpty()) { 283 | names += "|"; 284 | } 285 | names += name[i]; 286 | } 287 | if (!names.isEmpty()) { 288 | builder.append("&").append(PARAM_NAME).append(names); 289 | } 290 | 291 | } 292 | 293 | if (type != null) { 294 | Class someClass = PlaceType.class; 295 | try { 296 | someClass.getField(type.toUpperCase()); 297 | builder.append("&").append(PARAM_TYPE).append(type); 298 | 299 | } catch (Exception e) { 300 | 301 | throw new IllegalArgumentException( 302 | "'" + type + "' is invalid. All types are given in PlaceType class"); 303 | } 304 | } 305 | 306 | Log.e("Places", builder.toString()); 307 | return builder.toString(); 308 | } 309 | 310 | public static final class Builder { 311 | private String key; 312 | private double lat = -1; 313 | private double lng = -1; 314 | private int radius = -1; 315 | private String rankby; 316 | private String keyword; 317 | private int minprice = -1; 318 | private int maxprice = -1; 319 | private String[] name; 320 | private boolean opennow; 321 | private String type; 322 | private PlacesListener listener; 323 | private String language; 324 | private String countryCode; 325 | 326 | public Builder() { 327 | } 328 | 329 | 330 | public Builder key(String val) { 331 | key = val; 332 | return this; 333 | } 334 | 335 | public Builder latlng(double lat, double lng) { 336 | this.lat = lat; 337 | this.lng = lng; 338 | return this; 339 | } 340 | 341 | public Builder radius(int val) { 342 | radius = val; 343 | return this; 344 | } 345 | 346 | public Builder rankby(String val) { 347 | rankby = val; 348 | return this; 349 | } 350 | 351 | public Builder keyword(String val) { 352 | keyword = val; 353 | return this; 354 | } 355 | 356 | public Builder minprice(int min, int max) { 357 | minprice = min; 358 | maxprice = max; 359 | return this; 360 | } 361 | 362 | 363 | public Builder name(String... val) { 364 | name = val; 365 | return this; 366 | } 367 | 368 | public Builder name(List val) { 369 | name = new String[val.size()]; 370 | name = val.toArray(name); 371 | return this; 372 | } 373 | 374 | public Builder opennow(boolean val) { 375 | opennow = val; 376 | return this; 377 | } 378 | 379 | public Builder type(String val) { 380 | type = val; 381 | return this; 382 | } 383 | 384 | public Builder listener(PlacesListener val) { 385 | listener = val; 386 | return this; 387 | } 388 | 389 | public Builder language(String val) { 390 | language = val; 391 | return this; 392 | } 393 | 394 | /** 395 | * For example Locale is English, US (en_US) 396 | * 397 | * @param language will be en 398 | * @param countryCode will be US 399 | */ 400 | public Builder language(String language, String countryCode) { 401 | this.language = language; 402 | this.countryCode = countryCode; 403 | return this; 404 | } 405 | 406 | public NRPlaces build() { 407 | return new NRPlaces(this); 408 | } 409 | } 410 | } 411 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/Parser.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.util.Pair; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.net.MalformedURLException; 8 | import java.net.URL; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Noman on 8/25/2016. 13 | */ 14 | public abstract class Parser { 15 | private URL placeUrl; 16 | 17 | protected Parser(String placeUrl) { 18 | try { 19 | this.placeUrl = new URL(placeUrl); 20 | } catch (MalformedURLException e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | 26 | 27 | protected InputStream getInputStream() { 28 | try { 29 | return placeUrl.openConnection().getInputStream(); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | return null; 34 | } 35 | 36 | public abstract Pair> parseNearbyPlaces() throws PlacesException; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/Place.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.location.Location; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * Created by nor on 8/25/2016. 9 | */ 10 | public class Place { 11 | /** 12 | * coordinates of place 13 | */ 14 | private Location location; 15 | /** 16 | * icon of place, not all places have icon. 17 | */ 18 | private String icon; 19 | /** 20 | * name of place 21 | */ 22 | private String name; 23 | /** 24 | * place_id, can get place details using this id 25 | */ 26 | private String placeId; 27 | /** 28 | * types of place 29 | */ 30 | private String[] types; 31 | /** 32 | * near area of place 33 | */ 34 | private String vicinity; 35 | 36 | public Place() { 37 | } 38 | 39 | private Place(Builder builder) { 40 | setLocation(builder.location); 41 | setIcon(builder.icon); 42 | setName(builder.name); 43 | setPlaceId(builder.placeId); 44 | setTypes(builder.types); 45 | setVicinity(builder.vicinity); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Place{" + 51 | "location=" + location + 52 | ", icon='" + icon + '\'' + 53 | ", name='" + name + '\'' + 54 | ", placeId='" + placeId + '\'' + 55 | ", types=" + Arrays.toString(types) + 56 | ", vicinity='" + vicinity + '\'' + 57 | '}'; 58 | } 59 | 60 | /** 61 | * Get lat,lat - location of the place 62 | * 63 | * @return Location 64 | */ 65 | public Location getLocation() { 66 | return location; 67 | } 68 | 69 | /** 70 | * set location of place 71 | * 72 | * @param location 73 | */ 74 | public void setLocation(Location location) { 75 | this.location = location; 76 | } 77 | 78 | /** 79 | * Get icon of the place 80 | * Note : Not all places have icons. 81 | * 82 | * @return url of icon e.g. https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png 83 | */ 84 | public String getIcon() { 85 | return icon; 86 | } 87 | 88 | /** 89 | * set icon of location 90 | * 91 | * @param icon 92 | */ 93 | public void setIcon(String icon) { 94 | this.icon = icon; 95 | } 96 | 97 | /** 98 | * returns name of location 99 | * 100 | * @return name 101 | */ 102 | public String getName() { 103 | return name; 104 | } 105 | 106 | /** 107 | * set name of location 108 | * 109 | * @param name 110 | */ 111 | public void setName(String name) { 112 | this.name = name; 113 | } 114 | 115 | /** 116 | * get placeid of location. 117 | * placeid is string id and can be used to get details of a place 118 | * 119 | * @return 120 | */ 121 | public String getPlaceId() { 122 | return placeId; 123 | } 124 | 125 | /** 126 | * set place id 127 | * 128 | * @param placeId 129 | */ 130 | public void setPlaceId(String placeId) { 131 | this.placeId = placeId; 132 | } 133 | 134 | /** 135 | * returns types of location e.g. types ["cafe","food","point_of_interest","establishment"] 136 | * 137 | * @return String array types 138 | */ 139 | public String[] getTypes() { 140 | return types; 141 | } 142 | 143 | /** 144 | * set location types 145 | * 146 | * @param types 147 | */ 148 | public void setTypes(String[] types) { 149 | this.types = types; 150 | } 151 | 152 | /** 153 | * returns address/surrounding of place 154 | * 155 | * @return vicinity of place 156 | */ 157 | public String getVicinity() { 158 | return vicinity; 159 | } 160 | 161 | /** 162 | * set vicinity 163 | * 164 | * @param vicinity 165 | */ 166 | public void setVicinity(String vicinity) { 167 | this.vicinity = vicinity; 168 | } 169 | 170 | public double getLatitude(){ 171 | return location.getLatitude(); 172 | } 173 | 174 | public double getLongitude(){ 175 | return location.getLongitude(); 176 | } 177 | public static final class Builder { 178 | private Location location; 179 | private String icon; 180 | private String name; 181 | private String placeId; 182 | private String[] types; 183 | private String vicinity; 184 | 185 | public Builder() { 186 | } 187 | 188 | public Builder location(Location val) { 189 | location = val; 190 | return this; 191 | } 192 | 193 | public Builder icon(String val) { 194 | icon = val; 195 | return this; 196 | } 197 | 198 | public Builder name(String val) { 199 | name = val; 200 | return this; 201 | } 202 | 203 | public Builder placeId(String val) { 204 | placeId = val; 205 | return this; 206 | } 207 | 208 | public Builder types(String[] val) { 209 | types = val; 210 | return this; 211 | } 212 | 213 | public Builder vicinity(String val) { 214 | vicinity = val; 215 | return this; 216 | } 217 | 218 | public Place build() { 219 | return new Place(this); 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/PlaceType.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | /** 4 | * Created by Noman on 8/25/2016. 5 | * https://developers.google.com/places/supported_types 6 | */ 7 | public interface PlaceType { 8 | public String ACCOUNTING = "accounting"; 9 | public String AIRPORT = "airport"; 10 | public String AMUSEMENT_PARK = "amusement_park"; 11 | public String AQUARIUM = "aquarium"; 12 | public String ART_GALLERY = "art_gallery"; 13 | public String ATM = "atm"; 14 | public String BAKERY = "bakery"; 15 | public String BANK = "bank"; 16 | public String BAR = "bar"; 17 | public String BEAUTY_SALON = "beauty_salon"; 18 | public String BICYCLE_STORE = "bicycle_store"; 19 | public String BOOK_STORE = "book_store"; 20 | public String BOWLING_ALLEY = "bowling_alley"; 21 | public String BUS_STATION = "bus_station"; 22 | public String CAFE = "cafe"; 23 | public String CAMPGROUND = "campground"; 24 | public String CAR_DEALER = "car_dealer"; 25 | public String CAR_RENTAL = "car_rental"; 26 | public String CAR_REPAIR = "car_repair"; 27 | public String CAR_WASH = "car_wash"; 28 | public String CASINO = "casino"; 29 | public String CEMETERY = "cemetery"; 30 | public String CHURCH = "church"; 31 | public String CITY_HALL = "city_hall"; 32 | public String CLOTHING_STORE = "clothing_store"; 33 | public String CONVENIENCE_STORE = "convenience_store"; 34 | public String COURTHOUSE = "courthouse"; 35 | public String DENTIST = "dentist"; 36 | public String DEPARTMENT_STORE = "department_store"; 37 | public String DOCTOR = "doctor"; 38 | public String ELECTRICIAN = "electrician"; 39 | public String ELECTRONICS_STORE = "electronics_store"; 40 | public String EMBASSY = "embassy"; 41 | public String FINANCE = "finance"; 42 | public String FIRE_STATION = "fire_station"; 43 | public String FLORIST = "florist"; 44 | public String FUNERAL_HOME = "funeral_home"; 45 | public String FURNITURE_STORE = "furniture_store"; 46 | public String GAS_STATION = "gas_station"; 47 | public String GYM = "gym"; 48 | public String HAIR_CARE = "hair_care"; 49 | public String HARDWARE_STORE = "hardware_store"; 50 | public String HINDU_TEMPLE = "hindu_temple"; 51 | public String HOME_GOODS_STORE = "home_goods_store"; 52 | public String HOSPITAL = "hospital"; 53 | public String INSURANCE_AGENCY = "insurance_agency"; 54 | public String JEWELRY_STORE = "jewelry_store"; 55 | public String LAUNDRY = "laundry"; 56 | public String LAWYER = "lawyer"; 57 | public String LIBRARY = "library"; 58 | public String LIQUOR_STORE = "liquor_store"; 59 | public String LOCAL_GOVERNMENT_OFFICE = "local_government_office"; 60 | public String LOCKSMITH = "locksmith"; 61 | public String LODGING = "lodging"; 62 | public String MEAL_DELIVERY = "meal_delivery"; 63 | public String MEAL_TAKEAWAY = "meal_takeaway"; 64 | public String MOSQUE = "mosque"; 65 | public String MOVIE_RENTAL = "movie_rental"; 66 | public String MOVIE_THEATER = "movie_theater"; 67 | public String MOVING_COMPANY = "moving_company"; 68 | public String MUSEUM = "museum"; 69 | public String NIGHT_CLUB = "night_club"; 70 | public String PAINTER = "painter"; 71 | public String PARK = "park"; 72 | public String PARKING = "parking"; 73 | public String PET_STORE = "pet_store"; 74 | public String PHARMACY = "pharmacy"; 75 | public String PHYSIOTHERAPIST = "physiotherapist"; 76 | public String PLUMBER = "plumber"; 77 | public String POLICE = "police"; 78 | public String POST_OFFICE = "post_office"; 79 | public String REAL_ESTATE_AGENCY = "real_estate_agency"; 80 | public String RESTAURANT = "restaurant"; 81 | public String ROOFING_CONTRACTOR = "roofing_contractor"; 82 | public String RV_PARK = "rv_park"; 83 | public String SCHOOL = "school"; 84 | public String SHOE_STORE = "shoe_store"; 85 | public String SHOPPING_MALL = "shopping_mall"; 86 | public String SPA = "spa"; 87 | public String STADIUM = "stadium"; 88 | public String STORAGE = "storage"; 89 | public String STORE = "store"; 90 | public String SUBWAY_STATION = "subway_station"; 91 | public String SYNAGOGUE = "synagogue"; 92 | public String TAXI_STAND = "taxi_stand"; 93 | public String TRAIN_STATION = "train_station"; 94 | public String TRANSIT_STATION = "transit_station"; 95 | public String TRAVEL_AGENCY = "travel_agency"; 96 | public String UNIVERSITY = "university"; 97 | public String VETERINARY_CARE = "veterinary_care"; 98 | public String ZOO = "zoo"; 99 | 100 | } 101 | -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/PlacesException.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.util.Log; 4 | 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | /** 9 | * Created by Noman on 8/25/2016. 10 | */ 11 | public class PlacesException extends Exception { 12 | private static final String TAG = "PlacesException"; 13 | private static final String KEY_STATUS = "status"; 14 | 15 | private String statusCode; 16 | private String message; 17 | 18 | public PlacesException(JSONObject json){ 19 | if(json == null){ 20 | statusCode = ""; 21 | message = "Parsing error"; 22 | return; 23 | } 24 | try { 25 | statusCode = json.getString(KEY_STATUS); 26 | message = json.getString(KEY_STATUS); 27 | } catch (JSONException e) { 28 | Log.e(TAG, "JSONException while parsing PlacesException argument. Msg: " + e.getMessage()); 29 | } 30 | } 31 | 32 | public PlacesException(String msg){ 33 | message = msg; 34 | } 35 | 36 | @Override 37 | public String getMessage() { 38 | return message; 39 | } 40 | 41 | public String getStatusCode() { 42 | return statusCode; 43 | } 44 | } -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/PlacesListener.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import java.util.List; 4 | 5 | public interface PlacesListener { 6 | void onPlacesFailure(PlacesException e); 7 | 8 | void onPlacesStart(); 9 | 10 | void onPlacesSuccess(List places); 11 | 12 | void onPlacesFinished(); 13 | } -------------------------------------------------------------------------------- /placesAPI/src/main/java/noman/googleplaces/PlacesParser.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import android.location.Location; 4 | import android.util.Log; 5 | import android.util.Pair; 6 | 7 | import org.json.JSONArray; 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.InputStreamReader; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * A parser class that parse Google Places API JSON response 20 | * Created by Noman on 8/25/2016. 21 | */ 22 | public class PlacesParser extends Parser { 23 | private static final String GEOMETRY = "geometry"; 24 | private static final String ICON = "icon"; 25 | private static final String NAME = "name"; 26 | private static final String PLACE_ID = "place_id"; 27 | private static final String TYPES = "types"; 28 | private static final String VICINITY = "vicinity"; 29 | private static final String LOCATION = "location"; 30 | private static final String LAT = "lat"; 31 | private static final String LNG = "lng"; 32 | private static final String STATUS = "status"; 33 | private static final String STATUS_OK = "OK"; 34 | private static final String RESULTS = "results"; 35 | private static final String NEXT_PAGE_TOKEN = "next_page_token"; 36 | 37 | public PlacesParser(String placesUrl) { 38 | super(placesUrl); 39 | } 40 | 41 | 42 | public Pair> parseNearbyPlaces() throws PlacesException { 43 | final String result = convertStreamToString(this.getInputStream()); 44 | if (result == null) { 45 | throw new PlacesException("Result is null"); 46 | } 47 | 48 | try { 49 | JSONObject json = new JSONObject(result); 50 | if (!json.getString(STATUS).equals(STATUS_OK)) { 51 | throw new PlacesException(json); 52 | } 53 | 54 | JSONArray results = json.getJSONArray(RESULTS); 55 | List places = new ArrayList<>(); 56 | String nextPageToken = null; 57 | if (json.has(NEXT_PAGE_TOKEN)) { 58 | nextPageToken = json.getString(NEXT_PAGE_TOKEN); 59 | } 60 | 61 | for (int i = 0; i < results.length(); i++) { 62 | places.add(buildNearbyPlacefromJSON(results.getJSONObject(i))); 63 | } 64 | return new Pair<>(nextPageToken, places); 65 | } catch (JSONException e) { 66 | throw new PlacesException("JSONException. Msg: " + e.getMessage()); 67 | } 68 | 69 | } 70 | 71 | private Place buildNearbyPlacefromJSON(JSONObject jsonPlace) throws JSONException { 72 | Place place = new Place(); 73 | 74 | //get location 75 | JSONObject locationJson = jsonPlace.getJSONObject(GEOMETRY).getJSONObject(LOCATION); 76 | Location location = new Location("place"); 77 | location.setLatitude(locationJson.getDouble(LAT)); 78 | location.setLongitude(locationJson.getDouble(LNG)); 79 | place.setLocation(location); 80 | 81 | //get icon 82 | place.setIcon(jsonPlace.getString(ICON)); 83 | 84 | //getname 85 | place.setName(jsonPlace.getString(NAME)); 86 | 87 | //get place id 88 | place.setPlaceId(jsonPlace.getString(PLACE_ID)); 89 | 90 | //get types 91 | JSONArray typesArray = jsonPlace.getJSONArray(TYPES); 92 | String[] types = new String[typesArray.length()]; 93 | for (int i = 0; i < typesArray.length(); i++) { 94 | types[i] = typesArray.getString(i); 95 | } 96 | place.setTypes(types); 97 | 98 | //get vicinity 99 | place.setVicinity(jsonPlace.getString(VICINITY)); 100 | 101 | return place; 102 | } 103 | 104 | /** 105 | * Convert an inputstream to a string. 106 | * 107 | * @param input inputstream to convert. 108 | * @return a String of the inputstream. 109 | */ 110 | private String convertStreamToString(final InputStream input) { 111 | if (input == null) return null; 112 | 113 | final BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 114 | final StringBuilder sBuf = new StringBuilder(); 115 | 116 | String line; 117 | try { 118 | while ((line = reader.readLine()) != null) { 119 | sBuf.append(line); 120 | } 121 | } catch (IOException e) { 122 | Log.e("Places Error", e.getMessage()); 123 | } finally { 124 | try { 125 | input.close(); 126 | reader.close(); 127 | } catch (IOException e) { 128 | Log.e("Places Error", e.getMessage()); 129 | } 130 | } 131 | return sBuf.toString(); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /placesAPI/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Google Places 3 | 4 | -------------------------------------------------------------------------------- /placesAPI/src/test/java/noman/googleplaces/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package noman.googleplaces; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':placesAPI' 2 | --------------------------------------------------------------------------------